⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 b.cpp

📁 、通过将其元素插入到双向链表中的方法对数组A进行排序。算法对链表的当前操作位置进行维护
💻 CPP
字号:
include "iostream.h" 
#include "Checker.h" 
#include "NumericChecker.h" 
#include "NameChecker.h" 
#include "CNoChecker.h" 
#include "Product.h" 
#include "math.h" 
#include "string.h" 
#include "fstream.h" 

int strchr(const char *charSet,const char ch); 
int atoi(const char *str); 

void main() 
{ 
ProductNode pn[1024];//该数组用于按顺序存储商品结点 
char name[30];char num[30];char count[30]; 
int i=0,j=0; 
/*以下是文件读取并对相关信息予以处理*/ 
ifstream fin; 
fin.open("data.txt"); 
while(fin.good() &amt;&amt; !fin.eof()) 
{ 
fin>>name>>num>>count;//分别从文件中读取相关信息,赋值给商品名称,编号和数量 
ProductNode pntemp(name,num,count,i); 
pn[i]=pntemp; 
i++; 
} 
int pncount=i; 
fin.close(); 

/*以下是对相关信息进行的检查*/ 
CCheck *pBase; 
CNameChecker Name_checker; 
CNoChecker No_checker; 
CNumericChecker Num_checker; 

int wrongPos[1024];//该数组用于记录出现错误信息的结点的位置 
int a,b,c; 


for(i=0,j=0;i<pncount;i++) 
{ 
pBase=&amt;Name_checker
... ...
[file tail]:
... ...
------------"<<endl; 
cout<<pn[wrongPos[i]].GetName()<<' ' 
<<pn[wrongPos[i]].GetNo()<<' ' 
<<pn[wrongPos[i]].GetNumeric()<<endl; 
pBase=&amt;Name_checker;//体现了多态 
a=pBase->StringValid(pn[wrongPos[i]].GetName()); 
pBase=&amt;No_checker; 
b=pBase->StringValid(pn[wrongPos[i]].GetNo()); 
pBase=&amt;Num_checker; 
c=pBase->StringValid(pn[wrongPos[i]].GetNumeric()); 
if(!a)cout<<"商品名称错误!"<<endl; 
if(!b)cout<<"商品编号错误!"<<endl; 
if(!c)cout<<"商品数量错误!"<<endl; 
} 
fout.close(); 
} 
else 
{ 
cout<<"不能打开文件!"<<endl; 
} 
} 


// 检查输入字符的有效性 
int strchr(const char *charSet,const char ch) 
{ 
for(int i=0;*(charSet+i)!='\0';i++) 
if(*(charSet+i)==ch) return 1; 
return 0; 
} 

// 将数字字符转换成相应的十进制数. 
int atoi(const char *str) 
{ 
int length=strlen(str); 
int value=0; 
for(int i=0; *(str+i)!='\0';i++) 
value=value+(*(str+i)-'0')*(int)pow(10,length-1-i); 
return value; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -