




版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、精選優(yōu)質(zhì)文檔-傾情為你奉上#include<string>#include<iostream>#include<fstream>#include<cstdlib>#include<sstream>/#include<conio.h>#include<stdio.h>using namespace std;struct ProductNodestring NO;/型號(hào)string Name;/名稱string Brand;/品牌int Price;/賣出價(jià)int Quantity;/數(shù)量ProductNode*
2、next;/產(chǎn)品庫(kù)存鏈表class ProductListProductNode* first;/頭結(jié)點(diǎn)void InitInsert(ProductNode* s); /私有成員函數(shù),初始化時(shí)從文件讀入數(shù)據(jù)插入至鏈表public:ProductList()first=new ProductNode;first->next=NULL;/建立只有頭結(jié)點(diǎn)的空鏈表void ReadFile(); /營(yíng)業(yè)開(kāi)始,讀入文件void WriteFile(); /營(yíng)業(yè)結(jié)束,寫入文件void Insert(); /進(jìn)貨,插入結(jié)點(diǎn)void FindByNO(); /根據(jù)型號(hào)查找(結(jié)果不止一個(gè),所以用void
3、)void FindByName(); /根據(jù)名稱查找(同上)void FindByBrand(); /根據(jù)品牌查找(同上)bool Delete(); /提貨,刪除結(jié)點(diǎn)bool Modify(); /修改信息void PrintList()const;/遍歷單鏈表,按序號(hào)依次輸出各元素void DataResume(); /*數(shù)據(jù)恢復(fù)*ProductList(); /析構(gòu)函數(shù);void menu()cout<<" -交運(yùn)0902-n"<<" *第三方物流管理系統(tǒng)*n"<<" -n"<<
4、" 從下面的功能中選擇一個(gè)!n"<<" - - -n"<<" *顯示與查詢* *增刪改* *其他*n"<<" - - -n"<<" 1.顯示全部產(chǎn)品信息 5.進(jìn)貨(插入結(jié)點(diǎn)) 8.存盤n" <<" 2.按型號(hào)查詢 6.提貨(刪除結(jié)點(diǎn)) 9.營(yíng)業(yè)結(jié)束(存盤退出)n"<<" 3.按名稱查詢 7.修改產(chǎn)品信息 a.數(shù)據(jù)恢復(fù)n"<<" 4.按品牌查詢 0.退出(不存盤)n
5、"<<" -nn"/主程序int main()ProductList pl;cout<<"tt歡迎使用第三方物流管理系統(tǒng)n"cout<<"t1.開(kāi)始營(yíng)業(yè)nt2.退出n請(qǐng)選擇:"string choice;while(1)cin>>choice;if(choice0='2')exit(0);else if(choice0!='1')cout<<"此序號(hào)不存在,請(qǐng)重新輸入!n"else pl.ReadFile();/讀
6、入文件while(1)cout<<"請(qǐng)按回車?yán)^續(xù)."getchar();getchar();system("cls");/清屏menu();/顯示菜單cout<<"請(qǐng)輸入序號(hào):"cin>>choice;/選擇switch(choice0)case '1':pl.PrintList();break;/顯示全部產(chǎn)品信息case '2':pl.FindByNO();break;/按型號(hào)查詢case '3':pl.FindByName();break;/按名稱
7、查詢 case '4':pl.FindByBrand();break;/按品牌查詢case '5':pl.Insert();break;/進(jìn)貨(插入結(jié)點(diǎn))case '6':pl.Delete();break;/提貨(刪除結(jié)點(diǎn)) case '7':pl.Modify();break;/修改產(chǎn)品信息 case '8':pl.WriteFile();break;/存盤case '9':pl.WriteFile();cout<<"謝謝使用!n"exit(0);/營(yíng)業(yè)結(jié)束(存盤
8、退出)case 'a':pl.DataResume();break;/數(shù)據(jù)恢復(fù)case '0':cout<<"謝謝使用!n"exit(0); /退出(不存盤) default:cout<<"此序號(hào)不存在,請(qǐng)重新輸入!n"cout<<"請(qǐng)選擇:"/*在單鏈表中有序插入結(jié)點(diǎn)*/void ProductList:InitInsert(ProductNode* s) ProductNode* f=first;ProductNode* p=first->next;whil
9、e(p&&p->Price<s->Price)/f結(jié)點(diǎn)始終為p結(jié)點(diǎn)的前趨結(jié)點(diǎn),退出循環(huán)時(shí),s應(yīng)插入f結(jié)點(diǎn)后f=p;p=p->next;s->next=f->next;f->next=s;/*營(yíng)業(yè)開(kāi)始,讀入文件*/void ProductList:ReadFile()ifstream fin("product.txt");/輸入文件流對(duì)象if(fin.fail()cout<<"product.txt文件讀入錯(cuò)誤!n"cout<<"請(qǐng)按回車鍵退出."getc
10、har();exit(0);string oneline;/文件的一行ProductNode* r=first;while(getline(fin,oneline)/當(dāng)文件沒(méi)有結(jié)束,讀一行 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<<"產(chǎn)品信息如下:n" cout<<"型號(hào)"<<"tt"<<"名稱"<<"tt"<<"品牌"<<"tt"<<"單價(jià)"<<"tt"<<"數(shù)量"<<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");/輸出文件流對(duì)象 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" /析構(gòu)函數(shù) ProductList:ProductList() ProductNode* p=first; ProductNode* q; while(p) /釋放單鏈表的每一個(gè)結(jié)點(diǎn)的存儲(chǔ)空間 q=p; /暫存被釋放結(jié)點(diǎn) p=p->next; /工作指針p指向被釋放結(jié)點(diǎn)的下一個(gè)結(jié)點(diǎn),使單鏈表不斷開(kāi) delete q; void ProductList:FindByNO() string NO; bool flag=false;/假定沒(méi)有此產(chǎn)品 cout<<"輸入產(chǎn)品型號(hào):" cin>>NO; ProductNod
15、e* p; for(p=first->next;p;p=p->next) if(p->NO=NO) if(flag=false)/只輸出一次標(biāo)題 cout<<"查詢結(jié)果如下:n"<<"型號(hào)"<<"tt"<<"名稱"<<"tt"<<"品牌"<<"tt"<<"單價(jià)"<<"tt"<<&q
16、uot;數(shù)量"<<endl; cout<<p->NO<<"tt"<<p->Name<<"tt"<<p->Brand<<"tt"<<p->Price<<"tt"<<p->Quantity<<endl; flag=true;/存在產(chǎn)品 if(flag=false)cout<<"無(wú)此產(chǎn)品!" void ProductLi
17、st:FindByName() string Name; bool flag=false;/假定沒(méi)有 cout<<"輸入產(chǎn)品名稱:" cin>>Name; ProductNode* p=first->next; for(p=first->next;p;p=p->next) if(p->Name=Name) if(flag=false) cout<<"查詢結(jié)果如下:n"<<"型號(hào)"<<"tt"<<"名稱"
18、;<<"tt"<<"品牌"<<"tt"<<"單價(jià)"<<"tt"<<"數(shù)量"<<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<<"無(wú)此產(chǎn)品!" void ProductList:FindByBrand() string Brand; bool flag=false;/假定沒(méi)有 cout<<"輸入產(chǎn)品品牌:" cin>>Brand; ProductNode* p=first->next; for(p=first->next;p;p=p->next) if(p->Bran
20、d=Brand) if(flag=false) cout<<"查詢結(jié)果如下:n"<<"型號(hào)"<<"tt"<<"名稱"<<"tt"<<"品牌"<<"tt"<<"單價(jià)"<<"tt"<<"數(shù)量"<<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<<"無(wú)此產(chǎn)品!" void ProductList:Insert() PrintList(); string NO; cout<<"請(qǐng)輸入產(chǎn)品信息插入
22、(輸入產(chǎn)品型號(hào)時(shí)輸入z并按回車返回)n" cout<<"產(chǎn)品型號(hào):" cin>>NO; if(NO0='z')return; ProductNode* s=new ProductNode; s->NO=NO; cout<<"產(chǎn)品名稱:" cin>>s->Name; cout<<"產(chǎn)品品牌:" cin>>s->Brand; ProductNode* p=first->next; /工作指針p初始化 while (p&
23、amp;&!(p->NO=s->NO&&p->Name=s->Name&&p->Brand=s->Brand) /查找結(jié)點(diǎn) p=p->next; if(p)/此類產(chǎn)品存在 cout<<"此類產(chǎn)品存在!輸入進(jìn)貨數(shù)量n" cout<<"產(chǎn)品數(shù)量:" cin>>s->Quantity; if(s->Quantity<=0)cout<<"數(shù)據(jù)錯(cuò)誤!n"return; p->Quantity+
24、=s->Quantity; s->Price=p->Price;/便于修改日志文件 else/此類產(chǎn)品不存在 cout<<"產(chǎn)品單價(jià):" cin>>s->Price; if(s->Price<=0)cout<<"數(shù)據(jù)錯(cuò)誤!n"return; cout<<"產(chǎn)品數(shù)量:" cin>>s->Quantity; if(s->Quantity<=0)cout<<"數(shù)據(jù)錯(cuò)誤!n"return; Init
25、Insert(s); ofstream fout("diary.txt",ios:app);/向日志文件中添加記錄 fout<<"進(jìn)貨"<<"t"<<s->NO<<"t"<<s->Name<<"tt"<<s->Brand<<"t"<<s->Price<<"t"<<s->Quantity<&l
26、t;endl; cout<<"修改成功n" PrintList(); / /*提貨,數(shù)量減少or刪除結(jié)點(diǎn)*/ bool ProductList:Delete() PrintList(); cout<<"輸入賣出產(chǎn)品的信息!n" string NO,Name,Brand; cout<<"輸入型號(hào):(輸入z返回)" cin>>NO; if(NO0='z')return false; cout<<"產(chǎn)品名稱:" cin>>Name;
27、cout<<"產(chǎn)品品牌:" cin>>Brand; ProductNode* p=first->next; ProductNode* f=first; while (p&&!(p->NO=NO&&p->Name=Name&&p->Brand=Brand) /查找結(jié)點(diǎn) f=p; p=p->next; if (!p)/產(chǎn)品不存在 cout<<"此產(chǎn)品不存在!n" return false; else/產(chǎn)品存在 int Quantity; int
28、Price=p->Price;/修改日志用,因?yàn)閜結(jié)點(diǎn)要被刪除 cout<<"輸入提貨數(shù)量:" cin>>Quantity; while(Quantity>p->Quantity)cout<<"輸入的數(shù)量超出庫(kù)存量,請(qǐng)重新輸入!n"cin>>Quantity; if(Quantity<p->Quantity)p->Quantity-=Quantity; else/數(shù)量相等,刪除結(jié)點(diǎn) f->next=p->next; delete p; cout<<
29、"此產(chǎn)品被刪除!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; / /*數(shù)據(jù)恢復(fù)(讀取日志文件進(jìn)行相應(yīng)操作)*/ void ProductList:DataResume() ifstream fin("diary.txt"); string Type;/進(jìn)貨or提貨 string oneline; while(getline(fin,oneline)/當(dāng)文件沒(méi)有結(jié)束,讀一行 istringstream sin(oneline);/字符串流 ProductNode* s=new ProductNode; sin>>Type>>s
31、->NO>>s->Name>>s->Brand>>s->Price>>s->Quantity; if(Type="進(jìn)貨") ProductNode* p=first->next; /工作指針p初始化 while (p&&!(p->NO=s->NO&&p->Name=s->Name&&p->Brand=s->Brand) /查找第i個(gè)結(jié)點(diǎn) p=p->next; if(p)p->Quantity+=s
32、->Quantity;/此類產(chǎn)品存在 else InitInsert(s);/此類產(chǎn)品不存在 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個(gè)結(jié)點(diǎn) f=p; p=p->next; if (p)/產(chǎn)品存在 if(s->
33、;Quantity<p->Quantity)p->Quantity-=s->Quantity; else if(s->Quantity=p->Quantity)/數(shù)量相等,刪除結(jié)點(diǎn) f->next=p->next; delete p; cout<<"數(shù)據(jù)恢復(fù)成功n" PrintList(); /*修改產(chǎn)品信息*/ bool ProductList:Modify() PrintList(); cout<<"輸入要修改的產(chǎn)品信息!n" string NO,Name,Brand; cout
34、<<"產(chǎn)品型號(hào):(輸入'z'返回)" cin>>NO; if(NO0='z')return false; cout<<"產(chǎn)品名稱:" cin>>Name; cout<<"產(chǎn)品品牌:" cin>>Brand; ProductNode* p=first->next; ProductNode* f=first; while (p&&!(p->NO=NO&&p->Name=Name&
35、&p->Brand=Brand) /查找結(jié)點(diǎn) f=p; p=p->next; if (!p) /結(jié)點(diǎn)p不存在 cout<<"此產(chǎn)品不存在!n" return false; else /結(jié)點(diǎn)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<<"此產(chǎn)品信息如下:n" cout<<"型號(hào):"<<p->NO<<&qu
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 校園語(yǔ)言角交流合作合同(2篇)
- 《漢語(yǔ)閱讀教程》課件-教學(xué)課件:漢語(yǔ)閱讀教程L25
- 辦公設(shè)備維護(hù)與維修電子教案 模塊一 家庭辦公 項(xiàng)目二 日常業(yè)務(wù)處理
- 2025年全球與中國(guó)跨境支付行業(yè)概述及機(jī)遇調(diào)研報(bào)告
- 2025標(biāo)準(zhǔn)辦公室租賃合同概述
- 湖南省長(zhǎng)沙市雅禮教育集團(tuán)2024-2025學(xué)年高一下學(xué)期期中考試英語(yǔ)試題(有答案)
- 脊柱脊髓傷的臨床護(hù)理
- 小學(xué)立定跳遠(yuǎn)教學(xué)設(shè)計(jì)
- 2-2 細(xì)胞呼吸的原理和應(yīng)用(導(dǎo)學(xué)案)-2025年高考生物大一輪復(fù)習(xí)掃易錯(cuò)攻疑難學(xué)案
- 2025租房合同房東突然要求終止合同處理
- 美國(guó)加征關(guān)稅從多個(gè)角度全方位解讀關(guān)稅課件
- “皖南八?!?024-2025學(xué)年高一第二學(xué)期期中考試-英語(yǔ)(譯林版)及答案
- 一例脂肪液化切口的護(hù)理
- 2025屆嘉興市高三語(yǔ)文二模作文解析:智慧不會(huì)感到孤獨(dú)
- GB 15269-2025雪茄煙
- 規(guī)模養(yǎng)殖場(chǎng)十項(xiàng)管理制度
- 2025航天知識(shí)競(jìng)賽考試題庫(kù)(含答案)
- 路基路面壓實(shí)度評(píng)定自動(dòng)計(jì)算表-標(biāo)準(zhǔn)-
- 頭療培訓(xùn)知識(shí)課件
- 雙溪村移民安置區(qū)環(huán)境綜合整治工程 施工圖設(shè)計(jì)說(shuō)明
評(píng)論
0/150
提交評(píng)論