鱼C论坛

 找回密码
 立即注册
查看: 2197|回复: 2

[已解决]zuhe.exe 中的 0x771d15ee 处有未经处理的异常: 0xC0000005: 读取位置 0x0000002c ...

[复制链接]
发表于 2017-4-5 22:16:10 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
一段程序独立运行正常。去掉测试用的头文件,把它写进头文件后,运行到指定函数出现错误“zuhe.exe 中的 0x771d15ee 处有未经处理的异常: 0xC0000005: 读取位置 0x0000002c 时发生访问冲突“。鄙人水平有限,希望大家指导指导。
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;
  4. struct Product
  5. {
  6.         int pid;
  7.         string pname;
  8.         float pprice;
  9.         int pnum;
  10.         struct Product *next;
  11. }*Headpro;
  12. struct Customer
  13. {
  14.         int cid;
  15.         string cname;
  16.         string ctele;
  17.         float cjifen;
  18.         struct Customer *next;
  19. }*Headcus;
  20. void initP()//初始化
  21.         {
  22.                 Headpro=new struct Product;
  23.                 Headpro->pid=0000;
  24.                 Headpro->pname="water";
  25.                 Headpro->pnum=9;
  26.                 Headpro->pprice=1.5;
  27.                 Headpro->next=NULL;
  28.                 Headcus=new struct Customer;
  29.                 Headcus->cid=0000;
  30.                 Headcus->cname="jiajia";
  31.                 Headcus->ctele="1111111";
  32.                 Headcus->cjifen=0;
  33.                 Headcus->next=NULL;
  34. }
  35. struct Product *findpro(string a)//按名称查找商品
  36. {
  37.         struct Product *pro;
  38.         pro=new struct Product;
  39.         pro=Headpro->next;
  40.         while(pro!=NULL&&pro->pname!=a)
  41.         {
  42.                 pro=pro->next;
  43.         }
  44.         if(pro==NULL){cout<<"没有该商品"<<endl;return NULL;}
  45.         else return pro;
  46. }
  47. struct Product *findpro(int a)//按数目查找商品
  48. {
  49.         struct Product *pro;
  50.         pro=Headpro->next;
  51.         while(pro!=NULL&&pro->pnum<=a)
  52.         {
  53.                 pro=pro->next;
  54.         }
  55.         if(pro==NULL){cout<<"已找出所有符合要求的商品。"<<endl;return NULL;}
  56.         else return pro;
  57. }
  58. struct Product *endp()
  59. {
  60.         struct Product *prr;
  61.         prr=Headpro;
  62.         if(prr->next!=NULL)
  63.         {
  64.                 prr=prr->next;
  65.         }
  66.         return prr;
  67. }
  68. void addpro()//添加商品
  69. {
  70.         struct Product *have,*proo;
  71.         proo=new struct Product;
  72.         cout<<"请输入要添加商品名称"<<endl;
  73.         string name;
  74.         cin>>name;
  75.         have=findpro(name);
  76.         if(have!=NULL)
  77.                 {cout<<"已经存在此商品"<<endl;
  78.         return;}
  79.         have=endp();
  80.         have->next=proo;proo->next=NULL;
  81.         cout<<"请输入商品的具体信息"<<endl;
  82.         cout<<"商品ID"<<endl;cin>>proo->pid;
  83.         cout<<"商品名称"<<endl;cin>>proo->pname;
  84.         cout<<"商品价格"<<endl;cin>>proo->pprice;
  85.         cout<<"商品数目"<<endl;cin>>proo->pnum;
  86.         cout<<"添加商品成功"<<endl;
  87. }
  88. void showpro()//显示全部商品信息
  89. {
  90.         struct Product *pro;
  91.         if(Headpro->next!=NULL)
  92.         {
  93.         cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
  94.         do
  95.         {
  96.                 pro=Headpro->next;
  97.                 cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;
  98.         }
  99.         while(pro->next!=NULL);
  100.         }
  101. }

  102. void deletep()//删除商品
  103. {
  104.         cout<<"输入要删除的商品名称"<<endl;
  105.         string name;
  106.         cin>>name;
  107.         struct Product *pro,*temp;
  108.         pro=findpro(name);
  109.         if(pro==NULL)
  110.                 cout<<"不存在该商品"<<endl;
  111.         temp=Headpro;
  112.         while(temp->next!=pro)
  113.                 temp=temp->next;
  114.         temp->next=pro->next;
  115.         free(pro);
  116. }
  117. void check()//查询某一商品
  118. {
  119.         cout<<"输入所要查找商品名称"<<endl;
  120.         string name;
  121.         cin>>name;
  122.         struct Product *pro;
  123.         pro=findpro(name);
  124.         if(pro==NULL)
  125.                 cout<<"不存在该商品"<<endl;
  126.         else{
  127.                 cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
  128.                 cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;}
  129. }
  130. void rcheck()//查询少于一定数目的商品
  131. {
  132.         cout<<"输入要查询少于多少数目的商品"<<endl;
  133.         int i;
  134.         cin>>i;
  135.         struct Product *pro;
  136.         pro=findpro(i);
  137.         while(pro!=NULL){
  138.                 cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
  139.                 cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;}
  140. }
  141. void changep()//修改商品信息
  142. {
  143.         cout<<"输入要删除的商品名称"<<endl;
  144.         string name;
  145.         cin>>name;
  146.         struct Product *pro;
  147.         pro=findpro(name);
  148.         if(pro==NULL)
  149.                 cout<<"不存在该商品"<<endl;
  150.         int i=1;
  151.         while(i)
  152.         {
  153.         cout<<"请问你要修改该商品的:"<<endl;
  154.         cout<<"        1.ID 2.名称 3.价格 4.数目 5.不再修改"<<endl;
  155.         cin>>i;
  156.         switch(i)
  157.         {
  158.         case 1:cout<<"修改ID为:"<<endl;cin>>pro->pid;break;
  159.         case 2:cout<<"修改名称为:"<<endl;cin>>pro->pname;break;
  160.         case 3:cout<<"修改价格为:"<<endl;cin>>pro->pprice;break;
  161.         case 4:cout<<"修改数目为:"<<endl;cin>>pro->pnum;break;
  162.         case 5:i=0;break;
  163.         default:cout<<"请选择正确选项"<<endl;
  164.         }
  165.         }
  166. }
  167.        

  168. struct Customer *findcus(int a)//按会员代号查询信息
  169. {
  170.         struct Customer *cus;
  171.         cus=Headcus->next;
  172.         while(cus!=NULL&&cus->cid!=a)
  173.         {
  174.                 cus=cus->next;
  175.         }
  176.         if(cus==NULL){cout<<"没有该商品"<<endl;return NULL;}
  177.         else return cus;
  178. }
  179. void showcus()//显示会员信息
  180. {
  181.         struct Customer *cus;
  182.         cus=Headcus;
  183.         cout<<"会员代码"<<"  "<<"会员姓名"<<"  "<<"会员电话"<<"  "<<"会员积分"<<endl;
  184.         if(cus->next!=NULL)
  185.         {
  186.                 cus=cus->next;
  187.                 cout<<cus->cid<<'.'<<cus->cname<<','<<cus->ctele<<','<<cus->cjifen<<endl;
  188.         }
  189. }

  190. void deletec()//删除会员
  191. {
  192.         cout<<"输入要删除的会员ID"<<endl;
  193.         int i;
  194.         cin>>i;
  195.         struct Customer *cus,*temp;
  196.         cus=findcus(i);
  197.         if(cus==NULL)
  198.                 cout<<"不存在该会员"<<endl;
  199.         temp=Headcus;
  200.         while(temp->next!=cus)
  201.                 temp=temp->next;
  202.         temp->next=cus->next;
  203.         free(cus);
  204. }
  205. void changec()
  206. {
  207.         cout<<"请输入要更改会员代号"<<endl;
  208.         int i;
  209.         cin>>i;
  210.         struct Customer *cus;
  211.         cus=findcus(i);
  212.         if(cus==NULL)
  213.                 cout<<"不存在此会员"<<endl;
  214.         while(i)
  215.         {
  216.         cout<<"你要修改该会员的:"<<endl;
  217.         cout<<"1.代号"<<"2.姓名"<<"3.电话"<<"4.积分"<<"5.修改结束"<<endl;
  218.         switch(i)
  219.         {
  220.         case 1:cin>>cus->cid;break;
  221.         case 2:cin>>cus->cname;break;
  222.         case 3:cin>>cus->ctele;break;
  223.         case 4:cin>>cus->cjifen;break;
  224.         case 5:i=0;break;
  225.         default:cout<<"输入错误"<<endl;
  226.         }
  227. }
  228. }
  229. //以上是头文件,下面是主函数。
  230. #include<iostream>
  231. #include<fstream>
  232. #include<string>
  233. #include"shangpinhuiyuan.h"
  234. using namespace std;


  235. void initsystem()
  236. {
  237.        
  238.                 cout<<"欢迎光临本超市"<<endl;
  239. }

  240.         void managerwindow()
  241. {
  242.         int k=1;
  243.         while(k)
  244.         {
  245.         cout<<"请选择要执行的操作。"<<endl;
  246.         cout<<"1.查看全部商品。"<<endl;
  247.         cout<<"2.查看库存少于一定数量商品"<<endl;
  248.         cout<<"3.删除商品。"<<endl;
  249.         cout<<"4.添加商品。"<<endl;
  250.         cout<<"5.修改商品。"<<endl;
  251.         cout<<"6.查看会员信息。"<<endl;
  252.         cout<<"7.修改会员信息。"<<endl;
  253.         cout<<"8.删除会员。"<<endl;
  254.         cout<<"9.查询销售额。"<<endl;
  255.         cout<<"10.查询让利情况。"<<endl;
  256.         cout<<"11.退出系统。"<<endl;
  257.         cin>>k;
  258.         switch(k){
  259.         case 1:showpro();break;
  260.                 case 2:rcheck();break;
  261.                 case 3:deletep();break;
  262.                 case 4:addpro();break;
  263.                 case 5:changep();break;
  264.                 case 6:showcus();break;
  265.                 case 7:changec();break;
  266.                 case 8:deletec();break;
  267.                 case 9:cout<<"暂定"<<endl;
  268.         }
  269.         }
  270.         }

  271. void userwindow()
  272. {
  273.         int i=1;
  274.         while(i)
  275.         {cout<<"请选择你要的服务"<<endl;
  276.         cout<<"1.选购商品。"<<endl;
  277.                 cout<<"2.以管理员身份登入。"<<endl;
  278.                 cout<<"3.退出商店。"<<endl;
  279.         cin>>i;
  280.         switch(i){
  281.                 case 1:cout<<"1.选购商品。"<<endl;break;
  282.                 case 2:managerwindow();break;
  283.                 case 3:i=0;break;
  284.                 default:cout<<"输入错误,请重新输入"<<endl;
  285.                 }
  286. }
  287. }

  288.        

  289. int main()
  290. {
  291.        
  292.         initsystem();
  293. while(1)
  294.         {while(1)
  295. {userwindow();break;}
  296. managerwindow();break;
  297. }
  298.         return 0;
  299. }

  300.        
复制代码
最佳答案
2017-4-6 11:38:22
本帖最后由 lumber2388779 于 2017-4-6 14:29 编辑

1.函数定义不能放在头文件中的,头文件只是用于放函数声明,还有变量定义等等,不能用于函数定义,你可以写多一个C文件用于放这些函数定义,头文件写上这些声明就可以了
2.你的initP并没有任何地方调用到这个函数,你所有创建出来的结构体指针都是空的,并没有指向任何结构体,这是你报错最主要原因
3.Headcus和Headpro这两个指针复用率太高,容易出错,建议使用typedef定义结构体进行使用
还有其他一些小问题,这些靠你自己去找下了

shangpinhuiyuan.cpp

  1. #include<iostream>
  2. #include<fstream>
  3. #include<string>
  4. #include"shangpinhuiyuan.h"
  5. using namespace std;


  6. void initsystem()
  7. {

  8.         cout<<"欢迎光临本超市"<<endl;
  9. }

  10. void managerwindow()
  11. {
  12.         int k=1;
  13.         while(k)
  14.         {
  15.                 cout<<"请选择要执行的操作。"<<endl;
  16.                 cout<<"1.查看全部商品。"<<endl;
  17.                 cout<<"2.查看库存少于一定数量商品"<<endl;
  18.                 cout<<"3.删除商品。"<<endl;
  19.                 cout<<"4.添加商品。"<<endl;
  20.                 cout<<"5.修改商品。"<<endl;
  21.                 cout<<"6.查看会员信息。"<<endl;
  22.                 cout<<"7.修改会员信息。"<<endl;
  23.                 cout<<"8.删除会员。"<<endl;
  24.                 cout<<"9.查询销售额。"<<endl;
  25.                 cout<<"10.查询让利情况。"<<endl;
  26.                 cout<<"11.退出系统。"<<endl;
  27.                 cin>>k;
  28.                 switch(k){
  29. case 1:showpro();break;
  30. case 2:rcheck();break;
  31. case 3:deletep();break;
  32. case 4:addpro();break;
  33. case 5:changep();break;
  34. case 6:showcus();break;
  35. case 7:changec();break;
  36. case 8:deletec();break;
  37. case 9:cout<<"暂定"<<endl;
  38.                 }
  39.         }
  40. }

  41. void userwindow()
  42. {
  43.         int i=1;
  44.         while(i)
  45.         {cout<<"请选择你要的服务"<<endl;
  46.         cout<<"1.选购商品。"<<endl;
  47.         cout<<"2.以管理员身份登入。"<<endl;
  48.         cout<<"3.退出商店。"<<endl;
  49.         cin>>i;
  50.         switch(i){
  51. case 1:cout<<"1.选购商品。"<<endl;break;
  52. case 2:managerwindow();break;
  53. case 3:i=0;break;
  54. default:cout<<"输入错误,请重新输入"<<endl;
  55.         }
  56.         }
  57. }

  58. int main()
  59. {
  60.         initsystem();
  61.         initP();
  62.         while(1)
  63.         {
  64.                 while(1)
  65.                 {
  66.                         userwindow();
  67.                         break;
  68.                 }
  69.                 managerwindow();
  70.                 break;
  71.         }
  72.         return 0;
  73. }
复制代码


shangpinhuiyuan.h
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;

  4. typedef struct Product
  5. {
  6.         int pid;
  7.         string pname;
  8.         float pprice;
  9.         int pnum;
  10.         struct Product *next;
  11. }*Headpro,xHeadpro;
  12. typedef struct Customer
  13. {
  14.         int cid;
  15.         string cname;
  16.         string ctele;
  17.         float cjifen;
  18.         struct Customer *next;
  19. }*Headcus,xHeadcus;

  20. void initP();
  21. Headpro findpro(string a);
  22. Headpro findpro(int a);
  23. Headpro endp();
  24. void addpro();
  25. void showpro();

  26. void deletep();
  27. void check();
  28. void rcheck();
  29. void changep();


  30. Headcus findcus(int a);
  31. void showcus();
  32. void deletec();
  33. void changec();
复制代码


func.cpp
  1. #include<iostream>
  2. #include<string>
  3. #include"Test7.h"
  4. using namespace std;

  5. Headpro headpro = NULL;
  6. Headcus headcus = NULL;

  7. void initP()//初始化
  8. {
  9.         headpro=new xHeadpro;
  10.         headpro->pid=0000;
  11.         headpro->pname="water";
  12.         headpro->pnum=9;
  13.         headpro->pprice=1.5;
  14.         headpro->next=NULL;
  15.         headcus=new xHeadcus;
  16.         headcus->cid=0000;
  17.         headcus->cname="jiajia";
  18.         headcus->ctele="1111111";
  19.         headcus->cjifen=0;
  20.         headcus->next=NULL;
  21. }
  22. Headpro findpro(string a)//按名称查找商品
  23. {
  24.         Headpro pro;
  25.         pro=new xHeadpro;
  26.         pro=headpro->next;
  27.         while(pro!=NULL&&pro->pname!=a)
  28.         {
  29.                 pro=pro->next;
  30.         }
  31.         if(pro==NULL){cout<<"没有该商品"<<endl;return NULL;}
  32.         else return pro;
  33. }
  34. Headpro findpro(int a)//按数目查找商品
  35. {
  36.         Headpro pro;
  37.         pro=headpro->next;
  38.         while(pro!=NULL&&pro->pnum<=a)
  39.         {
  40.                 pro=pro->next;
  41.         }
  42.         if(pro==NULL){cout<<"已找出所有符合要求的商品。"<<endl;return NULL;}
  43.         else return pro;
  44. }
  45. Headpro endp()
  46. {
  47.         Headpro prr;
  48.         prr=headpro;
  49.         if(prr->next!=NULL)
  50.         {
  51.                 prr=prr->next;
  52.         }
  53.         return prr;
  54. }
  55. void addpro()//添加商品
  56. {
  57.         Headpro have,proo;
  58.         proo=new xHeadpro;
  59.         cout<<"请输入要添加商品名称"<<endl;
  60.         string name;
  61.         cin>>name;
  62.         have=findpro(name);
  63.         if(have!=NULL)
  64.         {cout<<"已经存在此商品"<<endl;
  65.         return;}
  66.         have=endp();
  67.         have->next=proo;proo->next=NULL;
  68.         cout<<"请输入商品的具体信息"<<endl;
  69.         cout<<"商品ID"<<endl;cin>>proo->pid;
  70.         cout<<"商品名称"<<endl;cin>>proo->pname;
  71.         cout<<"商品价格"<<endl;cin>>proo->pprice;
  72.         cout<<"商品数目"<<endl;cin>>proo->pnum;
  73.         cout<<"添加商品成功"<<endl;
  74. }
  75. void showpro()//显示全部商品信息
  76. {
  77.         Headpro pro;
  78.         if(headpro->next!=NULL)
  79.         {
  80.                 cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
  81.                 do
  82.                 {
  83.                         pro=headpro->next;
  84.                         cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;
  85.                 }
  86.                 while(pro->next!=NULL);
  87.         }
  88. }

  89. void deletep()//删除商品
  90. {
  91.         cout<<"输入要删除的商品名称"<<endl;
  92.         string name;
  93.         cin>>name;
  94.         Headpro pro,temp;
  95.         pro=findpro(name);
  96.         if(pro==NULL)
  97.                 cout<<"不存在该商品"<<endl;
  98.         temp=headpro;
  99.         while(temp->next!=pro)
  100.                 temp=temp->next;
  101.         temp->next=pro->next;
  102.         free(pro);
  103. }
  104. void check()//查询某一商品
  105. {
  106.         cout<<"输入所要查找商品名称"<<endl;
  107.         string name;
  108.         cin>>name;
  109.         Headpro pro;
  110.         pro=findpro(name);
  111.         if(pro==NULL)
  112.                 cout<<"不存在该商品"<<endl;
  113.         else{
  114.                 cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
  115.                 cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;}
  116. }
  117. void rcheck()//查询少于一定数目的商品
  118. {
  119.         cout<<"输入要查询少于多少数目的商品"<<endl;
  120.         int i;
  121.         cin>>i;
  122.         Headpro pro;
  123.         pro=findpro(i);
  124.         while(pro!=NULL){
  125.                 cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
  126.                 cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;}
  127. }
  128. void changep()//修改商品信息
  129. {
  130.         cout<<"输入要删除的商品名称"<<endl;
  131.         string name;
  132.         cin>>name;
  133.         Headpro pro;
  134.         pro=findpro(name);
  135.         if(pro==NULL)
  136.                 cout<<"不存在该商品"<<endl;
  137.         int i=1;
  138.         while(i)
  139.         {
  140.                 cout<<"请问你要修改该商品的:"<<endl;
  141.                 cout<<"        1.ID 2.名称 3.价格 4.数目 5.不再修改"<<endl;
  142.                 cin>>i;
  143.                 switch(i)
  144.                 {
  145.                 case 1:cout<<"修改ID为:"<<endl;cin>>pro->pid;break;
  146.                 case 2:cout<<"修改名称为:"<<endl;cin>>pro->pname;break;
  147.                 case 3:cout<<"修改价格为:"<<endl;cin>>pro->pprice;break;
  148.                 case 4:cout<<"修改数目为:"<<endl;cin>>pro->pnum;break;
  149.                 case 5:i=0;break;
  150.                 default:cout<<"请选择正确选项"<<endl;
  151.                 }
  152.         }
  153. }


  154. Headcus findcus(int a)//按会员代号查询信息
  155. {
  156.         Headcus cus;
  157.         cus=headcus->next;
  158.         while(cus!=NULL&&cus->cid!=a)
  159.         {
  160.                 cus=cus->next;
  161.         }
  162.         if(cus==NULL){cout<<"没有该商品"<<endl;return NULL;}
  163.         else return cus;
  164. }
  165. void showcus()//显示会员信息
  166. {
  167.         Headcus cus;
  168.         cus=headcus;
  169.         cout<<"会员代码"<<"  "<<"会员姓名"<<"  "<<"会员电话"<<"  "<<"会员积分"<<endl;
  170.         if(cus->next!=NULL)
  171.         {
  172.                 cus=cus->next;
  173.                 cout<<cus->cid<<'.'<<cus->cname<<','<<cus->ctele<<','<<cus->cjifen<<endl;
  174.         }
  175. }

  176. void deletec()//删除会员
  177. {
  178.         cout<<"输入要删除的会员ID"<<endl;
  179.         int i;
  180.         cin>>i;
  181.         Headcus cus,temp;
  182.         cus=findcus(i);
  183.         if(cus==NULL)
  184.                 cout<<"不存在该会员"<<endl;
  185.         temp=headcus;
  186.         while(temp->next!=cus)
  187.                 temp=temp->next;
  188.         temp->next=cus->next;
  189.         free(cus);
  190. }
  191. void changec()
  192. {
  193.         cout<<"请输入要更改会员代号"<<endl;
  194.         int i;
  195.         cin>>i;
  196.         Headcus cus;
  197.         cus=findcus(i);
  198.         if(cus==NULL)
  199.                 cout<<"不存在此会员"<<endl;
  200.         while(i)
  201.         {
  202.                 cout<<"你要修改该会员的:"<<endl;
  203.                 cout<<"1.代号"<<"2.姓名"<<"3.电话"<<"4.积分"<<"5.修改结束"<<endl;
  204.                 switch(i)
  205.                 {
  206.                 case 1:cin>>cus->cid;break;
  207.                 case 2:cin>>cus->cname;break;
  208.                 case 3:cin>>cus->ctele;break;
  209.                 case 4:cin>>cus->cjifen;break;
  210.                 case 5:i=0;break;
  211.                 default:cout<<"输入错误"<<endl;
  212.                 }
  213.         }
  214. }
复制代码


这是我修改的代码 你看下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2017-4-6 11:38:22 | 显示全部楼层    本楼为最佳答案   
本帖最后由 lumber2388779 于 2017-4-6 14:29 编辑

1.函数定义不能放在头文件中的,头文件只是用于放函数声明,还有变量定义等等,不能用于函数定义,你可以写多一个C文件用于放这些函数定义,头文件写上这些声明就可以了
2.你的initP并没有任何地方调用到这个函数,你所有创建出来的结构体指针都是空的,并没有指向任何结构体,这是你报错最主要原因
3.Headcus和Headpro这两个指针复用率太高,容易出错,建议使用typedef定义结构体进行使用
还有其他一些小问题,这些靠你自己去找下了

shangpinhuiyuan.cpp

  1. #include<iostream>
  2. #include<fstream>
  3. #include<string>
  4. #include"shangpinhuiyuan.h"
  5. using namespace std;


  6. void initsystem()
  7. {

  8.         cout<<"欢迎光临本超市"<<endl;
  9. }

  10. void managerwindow()
  11. {
  12.         int k=1;
  13.         while(k)
  14.         {
  15.                 cout<<"请选择要执行的操作。"<<endl;
  16.                 cout<<"1.查看全部商品。"<<endl;
  17.                 cout<<"2.查看库存少于一定数量商品"<<endl;
  18.                 cout<<"3.删除商品。"<<endl;
  19.                 cout<<"4.添加商品。"<<endl;
  20.                 cout<<"5.修改商品。"<<endl;
  21.                 cout<<"6.查看会员信息。"<<endl;
  22.                 cout<<"7.修改会员信息。"<<endl;
  23.                 cout<<"8.删除会员。"<<endl;
  24.                 cout<<"9.查询销售额。"<<endl;
  25.                 cout<<"10.查询让利情况。"<<endl;
  26.                 cout<<"11.退出系统。"<<endl;
  27.                 cin>>k;
  28.                 switch(k){
  29. case 1:showpro();break;
  30. case 2:rcheck();break;
  31. case 3:deletep();break;
  32. case 4:addpro();break;
  33. case 5:changep();break;
  34. case 6:showcus();break;
  35. case 7:changec();break;
  36. case 8:deletec();break;
  37. case 9:cout<<"暂定"<<endl;
  38.                 }
  39.         }
  40. }

  41. void userwindow()
  42. {
  43.         int i=1;
  44.         while(i)
  45.         {cout<<"请选择你要的服务"<<endl;
  46.         cout<<"1.选购商品。"<<endl;
  47.         cout<<"2.以管理员身份登入。"<<endl;
  48.         cout<<"3.退出商店。"<<endl;
  49.         cin>>i;
  50.         switch(i){
  51. case 1:cout<<"1.选购商品。"<<endl;break;
  52. case 2:managerwindow();break;
  53. case 3:i=0;break;
  54. default:cout<<"输入错误,请重新输入"<<endl;
  55.         }
  56.         }
  57. }

  58. int main()
  59. {
  60.         initsystem();
  61.         initP();
  62.         while(1)
  63.         {
  64.                 while(1)
  65.                 {
  66.                         userwindow();
  67.                         break;
  68.                 }
  69.                 managerwindow();
  70.                 break;
  71.         }
  72.         return 0;
  73. }
复制代码


shangpinhuiyuan.h
  1. #include<iostream>
  2. #include<string>
  3. using namespace std;

  4. typedef struct Product
  5. {
  6.         int pid;
  7.         string pname;
  8.         float pprice;
  9.         int pnum;
  10.         struct Product *next;
  11. }*Headpro,xHeadpro;
  12. typedef struct Customer
  13. {
  14.         int cid;
  15.         string cname;
  16.         string ctele;
  17.         float cjifen;
  18.         struct Customer *next;
  19. }*Headcus,xHeadcus;

  20. void initP();
  21. Headpro findpro(string a);
  22. Headpro findpro(int a);
  23. Headpro endp();
  24. void addpro();
  25. void showpro();

  26. void deletep();
  27. void check();
  28. void rcheck();
  29. void changep();


  30. Headcus findcus(int a);
  31. void showcus();
  32. void deletec();
  33. void changec();
复制代码


func.cpp
  1. #include<iostream>
  2. #include<string>
  3. #include"Test7.h"
  4. using namespace std;

  5. Headpro headpro = NULL;
  6. Headcus headcus = NULL;

  7. void initP()//初始化
  8. {
  9.         headpro=new xHeadpro;
  10.         headpro->pid=0000;
  11.         headpro->pname="water";
  12.         headpro->pnum=9;
  13.         headpro->pprice=1.5;
  14.         headpro->next=NULL;
  15.         headcus=new xHeadcus;
  16.         headcus->cid=0000;
  17.         headcus->cname="jiajia";
  18.         headcus->ctele="1111111";
  19.         headcus->cjifen=0;
  20.         headcus->next=NULL;
  21. }
  22. Headpro findpro(string a)//按名称查找商品
  23. {
  24.         Headpro pro;
  25.         pro=new xHeadpro;
  26.         pro=headpro->next;
  27.         while(pro!=NULL&&pro->pname!=a)
  28.         {
  29.                 pro=pro->next;
  30.         }
  31.         if(pro==NULL){cout<<"没有该商品"<<endl;return NULL;}
  32.         else return pro;
  33. }
  34. Headpro findpro(int a)//按数目查找商品
  35. {
  36.         Headpro pro;
  37.         pro=headpro->next;
  38.         while(pro!=NULL&&pro->pnum<=a)
  39.         {
  40.                 pro=pro->next;
  41.         }
  42.         if(pro==NULL){cout<<"已找出所有符合要求的商品。"<<endl;return NULL;}
  43.         else return pro;
  44. }
  45. Headpro endp()
  46. {
  47.         Headpro prr;
  48.         prr=headpro;
  49.         if(prr->next!=NULL)
  50.         {
  51.                 prr=prr->next;
  52.         }
  53.         return prr;
  54. }
  55. void addpro()//添加商品
  56. {
  57.         Headpro have,proo;
  58.         proo=new xHeadpro;
  59.         cout<<"请输入要添加商品名称"<<endl;
  60.         string name;
  61.         cin>>name;
  62.         have=findpro(name);
  63.         if(have!=NULL)
  64.         {cout<<"已经存在此商品"<<endl;
  65.         return;}
  66.         have=endp();
  67.         have->next=proo;proo->next=NULL;
  68.         cout<<"请输入商品的具体信息"<<endl;
  69.         cout<<"商品ID"<<endl;cin>>proo->pid;
  70.         cout<<"商品名称"<<endl;cin>>proo->pname;
  71.         cout<<"商品价格"<<endl;cin>>proo->pprice;
  72.         cout<<"商品数目"<<endl;cin>>proo->pnum;
  73.         cout<<"添加商品成功"<<endl;
  74. }
  75. void showpro()//显示全部商品信息
  76. {
  77.         Headpro pro;
  78.         if(headpro->next!=NULL)
  79.         {
  80.                 cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
  81.                 do
  82.                 {
  83.                         pro=headpro->next;
  84.                         cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;
  85.                 }
  86.                 while(pro->next!=NULL);
  87.         }
  88. }

  89. void deletep()//删除商品
  90. {
  91.         cout<<"输入要删除的商品名称"<<endl;
  92.         string name;
  93.         cin>>name;
  94.         Headpro pro,temp;
  95.         pro=findpro(name);
  96.         if(pro==NULL)
  97.                 cout<<"不存在该商品"<<endl;
  98.         temp=headpro;
  99.         while(temp->next!=pro)
  100.                 temp=temp->next;
  101.         temp->next=pro->next;
  102.         free(pro);
  103. }
  104. void check()//查询某一商品
  105. {
  106.         cout<<"输入所要查找商品名称"<<endl;
  107.         string name;
  108.         cin>>name;
  109.         Headpro pro;
  110.         pro=findpro(name);
  111.         if(pro==NULL)
  112.                 cout<<"不存在该商品"<<endl;
  113.         else{
  114.                 cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
  115.                 cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;}
  116. }
  117. void rcheck()//查询少于一定数目的商品
  118. {
  119.         cout<<"输入要查询少于多少数目的商品"<<endl;
  120.         int i;
  121.         cin>>i;
  122.         Headpro pro;
  123.         pro=findpro(i);
  124.         while(pro!=NULL){
  125.                 cout<<"商品ID"<<','<<"商品名称"<<','<<"商品价格"<<','<<"商品数目"<<endl;
  126.                 cout<<pro->pid<<"  "<<pro->pname<<"  "<<pro->pprice<<"  "<<pro->pnum<<endl;}
  127. }
  128. void changep()//修改商品信息
  129. {
  130.         cout<<"输入要删除的商品名称"<<endl;
  131.         string name;
  132.         cin>>name;
  133.         Headpro pro;
  134.         pro=findpro(name);
  135.         if(pro==NULL)
  136.                 cout<<"不存在该商品"<<endl;
  137.         int i=1;
  138.         while(i)
  139.         {
  140.                 cout<<"请问你要修改该商品的:"<<endl;
  141.                 cout<<"        1.ID 2.名称 3.价格 4.数目 5.不再修改"<<endl;
  142.                 cin>>i;
  143.                 switch(i)
  144.                 {
  145.                 case 1:cout<<"修改ID为:"<<endl;cin>>pro->pid;break;
  146.                 case 2:cout<<"修改名称为:"<<endl;cin>>pro->pname;break;
  147.                 case 3:cout<<"修改价格为:"<<endl;cin>>pro->pprice;break;
  148.                 case 4:cout<<"修改数目为:"<<endl;cin>>pro->pnum;break;
  149.                 case 5:i=0;break;
  150.                 default:cout<<"请选择正确选项"<<endl;
  151.                 }
  152.         }
  153. }


  154. Headcus findcus(int a)//按会员代号查询信息
  155. {
  156.         Headcus cus;
  157.         cus=headcus->next;
  158.         while(cus!=NULL&&cus->cid!=a)
  159.         {
  160.                 cus=cus->next;
  161.         }
  162.         if(cus==NULL){cout<<"没有该商品"<<endl;return NULL;}
  163.         else return cus;
  164. }
  165. void showcus()//显示会员信息
  166. {
  167.         Headcus cus;
  168.         cus=headcus;
  169.         cout<<"会员代码"<<"  "<<"会员姓名"<<"  "<<"会员电话"<<"  "<<"会员积分"<<endl;
  170.         if(cus->next!=NULL)
  171.         {
  172.                 cus=cus->next;
  173.                 cout<<cus->cid<<'.'<<cus->cname<<','<<cus->ctele<<','<<cus->cjifen<<endl;
  174.         }
  175. }

  176. void deletec()//删除会员
  177. {
  178.         cout<<"输入要删除的会员ID"<<endl;
  179.         int i;
  180.         cin>>i;
  181.         Headcus cus,temp;
  182.         cus=findcus(i);
  183.         if(cus==NULL)
  184.                 cout<<"不存在该会员"<<endl;
  185.         temp=headcus;
  186.         while(temp->next!=cus)
  187.                 temp=temp->next;
  188.         temp->next=cus->next;
  189.         free(cus);
  190. }
  191. void changec()
  192. {
  193.         cout<<"请输入要更改会员代号"<<endl;
  194.         int i;
  195.         cin>>i;
  196.         Headcus cus;
  197.         cus=findcus(i);
  198.         if(cus==NULL)
  199.                 cout<<"不存在此会员"<<endl;
  200.         while(i)
  201.         {
  202.                 cout<<"你要修改该会员的:"<<endl;
  203.                 cout<<"1.代号"<<"2.姓名"<<"3.电话"<<"4.积分"<<"5.修改结束"<<endl;
  204.                 switch(i)
  205.                 {
  206.                 case 1:cin>>cus->cid;break;
  207.                 case 2:cin>>cus->cname;break;
  208.                 case 3:cin>>cus->ctele;break;
  209.                 case 4:cin>>cus->cjifen;break;
  210.                 case 5:i=0;break;
  211.                 default:cout<<"输入错误"<<endl;
  212.                 }
  213.         }
  214. }
复制代码


这是我修改的代码 你看下
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2017-4-6 17:34:28 | 显示全部楼层
谢谢你的指导啊,新人第一次发帖,收到你那么精心的回复,感觉很温暖,很惊喜呢。。问题根据你的提示已经解决了。哈哈。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-5-22 17:27

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表