第三方物流管理信息系统C++_第1页
第三方物流管理信息系统C++_第2页
第三方物流管理信息系统C++_第3页
第三方物流管理信息系统C++_第4页
第三方物流管理信息系统C++_第5页
已阅读5页,还剩5页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、精选优质文档-倾情为你奉上#include<string>#include<iostream>#include<fstream>#include<cstdlib>#include<sstream>/#include<conio.h>#include<stdio.h>using namespace std;struct ProductNodestring NO;/型号string Name;/名称string Brand;/品牌int Price;/卖出价int Quantity;/数量ProductNode*

2、next;/产品库存链表class ProductListProductNode* first;/头结点void InitInsert(ProductNode* s); /私有成员函数,初始化时从文件读入数据插入至链表public:ProductList()first=new ProductNode;first->next=NULL;/建立只有头结点的空链表void ReadFile(); /营业开始,读入文件void WriteFile(); /营业结束,写入文件void Insert(); /进货,插入结点void FindByNO(); /根据型号查找(结果不止一个,所以用void

3、)void FindByName(); /根据名称查找(同上)void FindByBrand(); /根据品牌查找(同上)bool Delete(); /提货,删除结点bool Modify(); /修改信息void PrintList()const;/遍历单链表,按序号依次输出各元素void DataResume(); /*数据恢复*ProductList(); /析构函数;void menu()cout<<" -交运0902-n"<<" *第三方物流管理系统*n"<<" -n"<<

4、" 从下面的功能中选择一个!n"<<" - - -n"<<" *显示与查询* *增删改* *其他*n"<<" - - -n"<<" 1.显示全部产品信息 5.进货(插入结点) 8.存盘n" <<" 2.按型号查询 6.提货(删除结点) 9.营业结束(存盘退出)n"<<" 3.按名称查询 7.修改产品信息 a.数据恢复n"<<" 4.按品牌查询 0.退出(不存盘)n

5、"<<" -nn"/主程序int main()ProductList pl;cout<<"tt欢迎使用第三方物流管理系统n"cout<<"t1.开始营业nt2.退出n请选择:"string choice;while(1)cin>>choice;if(choice0='2')exit(0);else if(choice0!='1')cout<<"此序号不存在,请重新输入!n"else pl.ReadFile();/读

6、入文件while(1)cout<<"请按回车继续."getchar();getchar();system("cls");/清屏menu();/显示菜单cout<<"请输入序号:"cin>>choice;/选择switch(choice0)case '1':pl.PrintList();break;/显示全部产品信息case '2':pl.FindByNO();break;/按型号查询case '3':pl.FindByName();break;/按名称

7、查询 case '4':pl.FindByBrand();break;/按品牌查询case '5':pl.Insert();break;/进货(插入结点)case '6':pl.Delete();break;/提货(删除结点) case '7':pl.Modify();break;/修改产品信息 case '8':pl.WriteFile();break;/存盘case '9':pl.WriteFile();cout<<"谢谢使用!n"exit(0);/营业结束(存盘

8、退出)case 'a':pl.DataResume();break;/数据恢复case '0':cout<<"谢谢使用!n"exit(0); /退出(不存盘) default:cout<<"此序号不存在,请重新输入!n"cout<<"请选择:"/*在单链表中有序插入结点*/void ProductList:InitInsert(ProductNode* s) ProductNode* f=first;ProductNode* p=first->next;whil

9、e(p&&p->Price<s->Price)/f结点始终为p结点的前趋结点,退出循环时,s应插入f结点后f=p;p=p->next;s->next=f->next;f->next=s;/*营业开始,读入文件*/void ProductList:ReadFile()ifstream fin("product.txt");/输入文件流对象if(fin.fail()cout<<"product.txt文件读入错误!n"cout<<"请按回车键退出."getc

10、har();exit(0);string oneline;/文件的一行ProductNode* r=first;while(getline(fin,oneline)/当文件没有结束,读一行 istringstream sin(oneline);/字符串流 ProductNode* s=new ProductNode; sin>>s->NO>>s->Name>>s->Brand>>s->Price>>s->Quantity; InitInsert(s); void ProductList:PrintList

11、()const cout<<"产品信息如下:n" cout<<"型号"<<"tt"<<"名称"<<"tt"<<"品牌"<<"tt"<<"单价"<<"tt"<<"数量"<<endl; ProductNode* p=first->next; while(p) cou

12、t<<p->NO<<"tt"<<p->Name<<"tt"<<p->Brand<<"tt"<<p->Price<<"tt"<<p->Quantity<<endl; p=p->next; void ProductList:WriteFile() ofstream fout("product.txt");/输出文件流对象 ProductNode*

13、 p=first->next; while(p) fout<<p->NO<<"t"<<p->Name<<"tt"<<p->Brand<<"t"<<p->Price<<"t"<<p->Quantity<<endl; p=p->next; ofstream fout2("diary.txt");/清空日志文件 cout<<&qu

14、ot;存盘成功!n" /析构函数 ProductList:ProductList() ProductNode* p=first; ProductNode* q; while(p) /释放单链表的每一个结点的存储空间 q=p; /暂存被释放结点 p=p->next; /工作指针p指向被释放结点的下一个结点,使单链表不断开 delete q; void ProductList:FindByNO() string NO; bool flag=false;/假定没有此产品 cout<<"输入产品型号:" cin>>NO; ProductNod

15、e* p; for(p=first->next;p;p=p->next) if(p->NO=NO) if(flag=false)/只输出一次标题 cout<<"查询结果如下:n"<<"型号"<<"tt"<<"名称"<<"tt"<<"品牌"<<"tt"<<"单价"<<"tt"<<&q

16、uot;数量"<<endl; cout<<p->NO<<"tt"<<p->Name<<"tt"<<p->Brand<<"tt"<<p->Price<<"tt"<<p->Quantity<<endl; flag=true;/存在产品 if(flag=false)cout<<"无此产品!" void ProductLi

17、st:FindByName() string Name; bool flag=false;/假定没有 cout<<"输入产品名称:" cin>>Name; ProductNode* p=first->next; for(p=first->next;p;p=p->next) if(p->Name=Name) if(flag=false) cout<<"查询结果如下:n"<<"型号"<<"tt"<<"名称"

18、;<<"tt"<<"品牌"<<"tt"<<"单价"<<"tt"<<"数量"<<endl; cout<<p->NO<<"tt"<<p->Name<<"tt"<<p->Brand<<"tt"<<p->Price<<&qu

19、ot;tt"<<p->Quantity<<endl; flag=true; if(flag=false)cout<<"无此产品!" void ProductList:FindByBrand() string Brand; bool flag=false;/假定没有 cout<<"输入产品品牌:" cin>>Brand; ProductNode* p=first->next; for(p=first->next;p;p=p->next) if(p->Bran

20、d=Brand) if(flag=false) cout<<"查询结果如下:n"<<"型号"<<"tt"<<"名称"<<"tt"<<"品牌"<<"tt"<<"单价"<<"tt"<<"数量"<<endl; cout<<p->NO<<&quo

21、t;tt"<<p->Name<<"tt"<<p->Brand<<"tt"<<p->Price<<"tt"<<p->Quantity<<endl; flag=true; if(flag=false)cout<<"无此产品!" void ProductList:Insert() PrintList(); string NO; cout<<"请输入产品信息插入

22、(输入产品型号时输入z并按回车返回)n" cout<<"产品型号:" cin>>NO; if(NO0='z')return; ProductNode* s=new ProductNode; s->NO=NO; cout<<"产品名称:" cin>>s->Name; cout<<"产品品牌:" cin>>s->Brand; ProductNode* p=first->next; /工作指针p初始化 while (p&

23、amp;&!(p->NO=s->NO&&p->Name=s->Name&&p->Brand=s->Brand) /查找结点 p=p->next; if(p)/此类产品存在 cout<<"此类产品存在!输入进货数量n" cout<<"产品数量:" cin>>s->Quantity; if(s->Quantity<=0)cout<<"数据错误!n"return; p->Quantity+

24、=s->Quantity; s->Price=p->Price;/便于修改日志文件 else/此类产品不存在 cout<<"产品单价:" cin>>s->Price; if(s->Price<=0)cout<<"数据错误!n"return; cout<<"产品数量:" cin>>s->Quantity; if(s->Quantity<=0)cout<<"数据错误!n"return; Init

25、Insert(s); ofstream fout("diary.txt",ios:app);/向日志文件中添加记录 fout<<"进货"<<"t"<<s->NO<<"t"<<s->Name<<"tt"<<s->Brand<<"t"<<s->Price<<"t"<<s->Quantity<&l

26、t;endl; cout<<"修改成功n" PrintList(); / /*提货,数量减少or删除结点*/ bool ProductList:Delete() PrintList(); cout<<"输入卖出产品的信息!n" string NO,Name,Brand; cout<<"输入型号:(输入z返回)" cin>>NO; if(NO0='z')return false; cout<<"产品名称:" cin>>Name;

27、cout<<"产品品牌:" cin>>Brand; ProductNode* p=first->next; ProductNode* f=first; while (p&&!(p->NO=NO&&p->Name=Name&&p->Brand=Brand) /查找结点 f=p; p=p->next; if (!p)/产品不存在 cout<<"此产品不存在!n" return false; else/产品存在 int Quantity; int

28、Price=p->Price;/修改日志用,因为p结点要被删除 cout<<"输入提货数量:" cin>>Quantity; while(Quantity>p->Quantity)cout<<"输入的数量超出库存量,请重新输入!n"cin>>Quantity; if(Quantity<p->Quantity)p->Quantity-=Quantity; else/数量相等,删除结点 f->next=p->next; delete p; cout<<

29、"此产品被删除!n" cout<<"修改成功n" PrintList(); ofstream fout("diary.txt",ios:app);/向日志文件中添加记录 fout<<"提货"<<"t"<<NO<<"t"<<Name<<"tt"<<Brand<<"t"<<Price<<"t"

30、;<<Quantity<<endl; return true; / /*数据恢复(读取日志文件进行相应操作)*/ void ProductList:DataResume() ifstream fin("diary.txt"); string Type;/进货or提货 string oneline; while(getline(fin,oneline)/当文件没有结束,读一行 istringstream sin(oneline);/字符串流 ProductNode* s=new ProductNode; sin>>Type>>s

31、->NO>>s->Name>>s->Brand>>s->Price>>s->Quantity; if(Type="进货") ProductNode* p=first->next; /工作指针p初始化 while (p&&!(p->NO=s->NO&&p->Name=s->Name&&p->Brand=s->Brand) /查找第i个结点 p=p->next; if(p)p->Quantity+=s

32、->Quantity;/此类产品存在 else InitInsert(s);/此类产品不存在 if(Type="提货") ProductNode* p=first->next; /工作指针p初始化 ProductNode* f=first; /工作指针p初始化 while (p&&!(p->NO=s->NO&&p->Name=s->Name&&p->Brand=s->Brand) /查找第i-1个结点 f=p; p=p->next; if (p)/产品存在 if(s->

33、;Quantity<p->Quantity)p->Quantity-=s->Quantity; else if(s->Quantity=p->Quantity)/数量相等,删除结点 f->next=p->next; delete p; cout<<"数据恢复成功n" PrintList(); /*修改产品信息*/ bool ProductList:Modify() PrintList(); cout<<"输入要修改的产品信息!n" string NO,Name,Brand; cout

34、<<"产品型号:(输入'z'返回)" cin>>NO; if(NO0='z')return false; cout<<"产品名称:" cin>>Name; cout<<"产品品牌:" cin>>Brand; ProductNode* p=first->next; ProductNode* f=first; while (p&&!(p->NO=NO&&p->Name=Name&

35、&p->Brand=Brand) /查找结点 f=p; p=p->next; if (!p) /结点p不存在 cout<<"此产品不存在!n" return false; else /结点p存在 ofstream fout("diary.txt",ios:app);/向日志文件中添加记录fout<<"提货"<<"t"<<p->NO<<"t"<<p->Name<<"tt"<<p->Brand<<"t"<<p->Price<<"t"<<p->Quantity<<endl; int Price,Quantity; cout<<"此产品信息如下:n" cout<<"型号:"<<p->NO<<&qu

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论