


版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、商品銷售統(tǒng)計1. 需求和規(guī)格說明1.1 問題描述 編寫商品銷售統(tǒng)計程序,商品的信息有商品名、計量單位(重量 或件)、單價。所有商品的信息事先已存入計算機(jī),屏幕上顯示所有 商品的名稱,選擇商品名,輸入商品計量單位(如重量、件數(shù)等) , 根據(jù)單價算出總價。 客戶一次可能購買多種商品, 程序應(yīng)計算出客戶 應(yīng)付的錢款數(shù)。1.2 基本要求程序分為兩個部分: 第一部分用于輸入商品的信息并允許修改和 刪除;第二部分實現(xiàn)銷售統(tǒng)計。 程序運行時由用戶選擇進(jìn)入哪一部分 功能,并能在運行時在兩部分之間切換。第二部分運行時,首先顯示 所有商品名稱及代碼(商品數(shù)目較多時,應(yīng)考慮分屏顯示) ,用戶輸 入商品代碼及商品重量
2、或件數(shù), 用戶一次操作可輸入若干商品的購買 信息,然后輸入一個特殊的代碼(如“ -1 ”)表示本次購物結(jié)束。此 時,程序計算出應(yīng)付錢款數(shù)并顯示。2. 設(shè)計2.1 文字描述先定義一個商品類 GOODS ,含有每種商品基本信息即商品名、 計量單位(重量或件) 、單價、商品總量皆被定義為私有數(shù)據(jù)成員; 公有成員部分有該類構(gòu)造函數(shù)以及其他友元函數(shù)。為了完成程序基本要求, 采用嵌套系統(tǒng)思想, 即先構(gòu)造一個總的 系統(tǒng)商品銷售統(tǒng)計工程,通過 switch 語句可選擇進(jìn)入其下面兩 個子系統(tǒng)商品信息管理系統(tǒng)和商品銷售系統(tǒng), 以完成程序要求的 兩個部分的功能。其中,每個子系統(tǒng)又可根據(jù) switch 語句進(jìn)行選擇
3、操作,并能實現(xiàn)在兩個子系統(tǒng)之間的切換。2.2圖示類名類別類型名稱說明privatestri ngn ame商品名privatestri ngun it計量單位privatedoubleprice per un it單價privatedoubleamount商品總數(shù)publicGOODS)構(gòu)造函數(shù)GOODSfriendviodsort()排序,使得信息為空的商品沉底friendviodin put gds mesg()底層函數(shù):錄入商品信息friendviodMessage modify()底層函數(shù):修改商品信息friendviodMessage delete()底層函數(shù):刪除商品信息frien
4、dviodGoods Message Ma nage()中層函數(shù):1.商品信息管理系統(tǒng)friendviodGoods Sale()中層函數(shù):2.商品銷售系統(tǒng)friendviodWORK()高層函數(shù):商品銷售統(tǒng)計工程3. 用戶手冊根據(jù)提示選擇操作即可,具體為:(1)程序運行時,首先要求初始化商品信息,即需添加銷售的商品名稱、單價等;(2 )根據(jù)需求選擇進(jìn)入商品信息管理系統(tǒng)或者商品銷售系統(tǒng), 其中前者可進(jìn)行的操作有:錄入新商品信息、修改商品信息、刪除商 品信息等,后者為用戶提供購買商品功能,只需根據(jù)提示操作即可; 注意:請輸入與程序要求相應(yīng)的選擇以及正確的格式,不要超出程序給定的范圍!4. 附錄源
5、代碼#in clude<iostream>#in clude<stri ng>#in clude<fstream>using n amespace std;int choice;class GOODSprivate:string name; / 商品名string unit; / 計量單位double price_per_unit; / 單價double amount; / 商品總數(shù)public:GOODS(); / 構(gòu)造函數(shù)/ 排序函數(shù),使得信息為空的商品類數(shù)組元素沉底,不為空的排在前面(被 "刪除商品信息函數(shù) "調(diào)用)friend v
6、oid sort(GOODS array,int size);friend void input_gds_mesg(GOODS goods1,int size); / 底層函 數(shù):錄入商品信息 (從屬于商品信息管理系統(tǒng) )friend void Message_modify(GOODS goods2,int size); / 底層函 數(shù):修改商品信息(從屬于商品信息管理系統(tǒng))friend void Message_delete(GOODS goods3,int size); / 底層函 數(shù):刪除商品信息(從屬于商品信息管理系統(tǒng))friend void Goods_Message_Manage(
7、GOODS Goods1,int size); / 中層函數(shù): 1.商品信息管理系統(tǒng)(從屬于商品銷售統(tǒng)計工程)friend void Goods_Sale(GOODS Goods2,int size); / 中層函數(shù): 2.商品銷售系統(tǒng)(從屬于商品銷售統(tǒng)計工程)friend void WORK(GOODS Goods,int size); / 高層函數(shù):商品銷 售統(tǒng)計工程;GOODS:GOODS()name="0"unit="0"price_per_unit=0.0;amount=0;void input_gds_mesg(GOODS goods1,in
8、t size)/ 底層函數(shù):息函數(shù) (從屬于商品信息管理系統(tǒng) )int i,j,m=0;int s=size;int n=size;string l;for(i=0;i<s;i+)if(!="0")m+;else if(="0")s=m;for(j=m;j<n;j+)cout<<"錄入商品信"<<endl;cout<<">>> 請輸入第 "<<j+1<<"cin>
9、>;種商品的名稱:"<<endl;cout<<endl;cout<<">>> 請輸入第 "<<j+1<<" cin>>goods1j.unit;cout<<endl;cout<<">>> 請輸入第 "<<j+1<<"cin>>goods1j.price_per_unit;種商品的計量單位:種商品的單價(元)cout<<
10、endl;cout<<">>> 請輸入第 "<<j+1<<" 種商品的數(shù)量:cin>>goods1j.amount;cout<<"cout<<endl;修改商品信謝謝使用,cout<<"_ 繼續(xù)錄入商品信息?( y/n )_" cin>>l;cout<<endl;if(l="n"|l="N")n=j;else if(l="y"|l="Y&qu
11、ot;);cout<<"_ 商品信息錄入完成! "<<endl<<endl; cout<<""<<endl;return;void Message_modify(GOODS goods2,int size) / 底層函數(shù): 息函數(shù)(從屬于商品信息管理系統(tǒng))if(="0")cout<<"Caution: 當(dāng)前無商品信息,請返回更新! (y/n ) string c;cin>>c;cout<<"&qu
12、ot;<<endl;cout<<endl;if(c="y"|c="Y")Goods_Message_Manage(goods2,size);WORK(goods2,size);elsecout<<">>>>>>>>>>>>>>>>>>>>>>>>>>> 祝您愉快!再見! <<<<<<<<<<
13、<<<<<<<<<<<<<<<<"<<endl;exit(0);string p,q;int n;string unit;string name;double price;double amount;int choice2;dodocout<<" 商 品 信 息 列 表 "<<endl<<endl;coutvv"t 商品編號t商品名稱t商品單價t商品余量 "<<endl<<end
14、l;int i,m=0;int s=size;for(i=0;i<s;i+)if(!="0")m+;else if(="0")s=m; for(i=0;i<m;i+)cout<<"t"<<i+1<<"."<<"t"<<"t"<<<<"t"<<goods2i.price_per_u
15、nit<<"元"<<"/"<<goods2i.unit<<"t"<<goods2i.amount<<goods2i.unit<< endl<<endl; cout<<""<<endl;cout<<">>> 請輸入您想修改信息的商品編號: _"/int n; cin>>n; cout<<""<<
16、endl;cout<<endl;cout<<"_ 您 想 修 改 信 息 的 商 品 為 :"<<n<<"."<<<<"(y/n )/string p; cin>>p;cout<<endl;if(p="y"|p="Y") cout<<""<<endl;docout<<"1. 修改商品名稱 "<<e
17、ndl<<endl;cout<<"2. 修改商品計量單位 "<<endl<<endl;cout<<"3. 修改商品單價(元) "<<endl<<endl;cout<<"4. 修改商品數(shù)量 "<<endl<<endl;cout<<""<<endl;cout<<">>> 請輸入您的選擇( 1-4 ):_" cin>>
18、choice2;cout<<endl;switch(choice2) case 1:cout<<">>> 請 輸 入 "<<n<<" 號 商 品 "<<<<"的名稱: _"/ !string name;cin>>name;=name;break; case 2: cout<<">>> 請 輸 入 "<<n<<
19、;" 號 商 品 "<<<<"的計量單位: _"/ ! string unit;cin>>unit;goods2n-1.unit=unit;break; case 3:cout<<">>> 請 輸 入 "<<n<<" 號 商 品 "<<<<"的單價: _"/ ! double price;cin>>price;goo
20、ds2n-1.price_per_unit=price; break;case 4: cout<<">>> 請 輸 入 "<<n<<" 號 商 品 "<<<<"的數(shù)量: _"/ ! int num;cin>>amount;goods2n-1.amount=amount;break;default:cout<<"Caution: 對不起,輸入有誤,請從新輸入! " break;while(
21、choice2!=1&&choice2!=2&&choice2!=3&&choice2!=4);while(p="n"|p="N");cout<<""<<endl;cout<<"_ 繼續(xù)修改商品信息( y/n )? _"/string q;cin>>q; cout<<endl;while(q="y"|q="Y");cout<<"_商 品 信 息 修
22、 改 完 成 !Jcout<<" "<<endl;return;void sort(GOODS array,int size)/ 排序函數(shù),使得信息為空的商品類數(shù)組元素沉底,不為空的排在前面(被 "刪除商品信息函數(shù) " 調(diào)用)int i,j;GOODS temp;for(i=0;i<size-1;i+)for(j=0;j<size-1-i;j+)if(="0"&&arrayj+1.name!="0")temp=arrayj;arrayj=ar
23、rayj+1;arrayj+1=temp;return;void Message_delete(GOODS goods3,int size)/ 底層函數(shù):刪除商品信息函數(shù)(從屬于商品信息管理系統(tǒng))if(="0")cout<<"Caution: 對不起,當(dāng)前無商品信息,請返回更新! ( y/n )_" string c;cin>>c;cout<<""<<endl;cout<<endl;if(c="y"|c="Y")
24、 Goods_Message_Manage(goods3,size); WORK(goods3,size);else cout<<">>>>>>>>>>>>>>>>>>>>>>>>>>> 謝謝使用, 祝您愉快!再見! <<<<<<<<<<<<<<<<<<<<<<<<<
25、;<"<<endl;exit(0);string p,q;int n;string unit;/double price;dodocout<<" 商 品 信 息 列 表 "<<endl<<endl;coutvv"t 商品編號t商品名稱t商品單價t商品余量 "<<endl<<endl;int i,m=0;int s=size;for(i=0;i<s;i+) if(!="0")m+;else if(
26、="0")s=m;for(i=0;i<m;i+)cout<<"t"<<i+1<<"t"<<"t"<<<<"t"<<goods3i.price_per_unit<<"元"<<"/"<<goods3i.unit<<"t"<<goods3i.amount<<g
27、oods3i.unit<<endl<<endl;cout<<""<<endl;cout<<">>> 請輸入您想刪除信息的商品編號: /int n;cin>>n;cout<<endl;cout<<"_您 想 刪 除 信 息 的 商"<<n<<"."<<<<"(y/n ) _"/string p;cin>>p;
28、cout<<endl;if(p="y"|p="Y")="0"goods3n-1.unit="0" goods3n-1.price_per_unit=0.0;goods3n-1.amount=0; cout<<""<<endl;while(p="n"|p="N");cout<<"_ 繼續(xù)刪除商品信息( y/n )? _"/ string q; cin>>
29、;q; cout<<endl;while(q="y"|q="Y");cout<<"_商 品 信 息 刪 除 完Jcout<<" "<<endl;sort(goods3,size);return;品為:中層函數(shù): M.void Goods_Message_Manage(GOODS Goods1,int size) / 商品信息管理系統(tǒng)(從屬于商品銷售統(tǒng)計工程)int choice1;docout<<""<<endl;cout<&l
30、t;""<<endl;cout<<"商品信息管理系統(tǒng)"<<endl;cout<<""<<endl;cout<<""<<endl<<endl;cout<<">>>>>>>>>>>>>>>>>>>>>>請選擇您要執(zhí)行 的 操 作 <<<<<&l
31、t;<<<<<<<<<<<<<<<"<<endl<<endl;cout<<"1. 錄入新商品信息"<<endl;cout<<"2.修改商品信息"<<endl;cout<<"3.刪除商品信息"<<endl;cout<<"4. 返 回"<<endl;cout<<"0.退出cout&
32、lt;<""<<endl;cout<<">>> 請輸入您的選擇:(0-4 )_"cin>>choice1;cout<<endl;switch(choice1)case 1: input_gds_mesg(Goods1,size); break;case 2:Message_modify(Goods1,size); break;case 3:Message_delete(Goods1,size); break;case 4:WORK(Goods1,size); break;case 0
33、:cout<<">>>>>>>>>>>>>>>>>>>>>>>>>>> 謝謝使用, 祝您愉快!再見! <<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;exit(0);break;default:cout<<
34、" 對 不 起 , 您 的 輸 入 有 誤 , 請 重 新 進(jìn) 行 選 擇 ! "<<endl<<endl;break; while(choice1!=0&&choice1!=1&&choice1!=2&&choice1!=3&&ch oice1!=4);return;void Goods_Sale(GOODS Goods2,int size) / 中層函數(shù):S.商品銷售系統(tǒng) (從屬于商品銷售統(tǒng)計工程)if(G="0")cout<<&
35、quot;Caution: 對不起,當(dāng)前無商品信息,請返回更新! ( y/n )_" string c;cin>>c; cout<<""<<endl;cout<<endl;if(c="y"|c="Y") Goods_Message_Manage(Goods2,size); WORK(Goods2,size);else cout<<">>>>>>>>>>>>>>>>
36、;>>>>>>>>>>> 謝謝使用, 祝您愉快!再見! <<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl;exit(0);string p,q;int num1000,amount1000; /num 存放所要 購買商品的編號, amount 存放購買的每種商品數(shù)量int j=0,f=0,r=0;string unit;double m
37、oney=0.0;dodocout<<"cout<<" 商 品 信 息 列 表 "<<endl<<endl;coutvv"t 商品編號t商品名稱t商品單價t商品余量 "<<endl<<endl;int i,m=0;int s=size;for(i=0;i<s;i+) if(G!="0")m+;else if(G="0")s=m;for(i=0;i<m;i+)cout<<
38、;"t"<<i+1<<"t"<<"t"<<G<<"t"<<Goods2i.price_per_unit<<"元"<<"/"<<Goods2i.unit<<"t"<<Goods2i.amount<<Goods2i.unit<<endl<<endl;cout<<
39、""<<endl;cout<<">>> 請輸入您想購買的商品的編號(輸入“0”結(jié)束):"<<endl;/int numsize;for(j=0;numj-1!=0;j+) cout<<"-" cin>>numj;/do/cin>>numj;/j+;/while(numj-1!=0);cout<<"_ 您想購買的商品為: "<<endl<<endl; cout<<"&qu
40、ot;<<endl;cout<<"_ 商品編號 t 商品名稱 "<<endl<<endl; for(f=0;f<j-1;f+)if(numf!=0)cout<<numf<<"t"<<"t"<<G<<endl<<endl;cout<<""<<endl;cout<<"_ 確認(rèn)( y/n )? / string p;ci
41、n>>p;cout<<""<<endl;cout<<endl;if(p="y"|p="Y")cout<<">>> 請輸入您想購買的商品數(shù)量: "<<endl<<endl; cout<<"cout<<" 商品編號 t 商品名稱 t 購買數(shù)量 "<<endl<<endl; for(f=0,r=0;(f<j-1)&&(r&
42、lt;size);f+,r+)if(numf!=0)cout<<numf<<"t"<<"t"<<G<<"t" cin>>amountr;Goods2numf-1.amount-=amountr; cout<<endl;cout<<""<<endl;while(p="n"|p="N");cout<<"_ 您購買的商品信
43、息如下 :"<<endl<<endl; cout<<""<<endl;cout<<"t 商 品 編 號 t 商 品 名 稱 t 商 品 單 價 t 購 買 數(shù) 量 "<<endl<<endl;for(f=0,r=0;(f<j-1)&&(r<size);f+,r+)if(numf!=0)cout<<"t"<<numf<<"t"<<"t&qu
44、ot;<<G<<"t" <<Goods2numf-1.price_per_unit<<" 元 "<<"/"<<Goods2numf-1.unit<<"t"<<amountr<<Goods2numf- 1.unit<<endl<<endl; cout<<""<<endl;for(f=0,r=0;(f<j-1
45、)&&(r<size);f+,r+)if(numf!=0) money+=Goods2numf-1.price_per_unit*amountr;coutvv"_ 您一共應(yīng)支付"vvmoney<<"元."<<endl<<endl;cout«""<<e ndl;cout<<"_ 繼續(xù)購物( y/n )? _"/ string q; cin>>q;cout<<endl;while(q="y&qu
46、ot;|q="Y");cout<<" >>>>>>>>>>>>>>>>>>>>>>>>>>>謝謝惠顧, 歡迎再來! <<<<<<<<<<<<<<<<<<<<<<<<<<"<<endl<<endl;WORK(
47、Goods2,size);void WORK(GOODS Goods,int size)/ 高層函數(shù):商品銷售統(tǒng)計工程docout<<">>>>>>>>>>>>>>>>>>>>>>>>>請 選 擇 您 要1. 商品信息管理系統(tǒng)執(zhí) 行 的 操 作 <<<<<<<<<<<<<<<<<<<<<<<
48、;<"<<endl;cout<<""<<endl;cout<<"2. 商品銷售系統(tǒng)"<<endl;cout<<" 0. 退 出Jcout<<""<<endl;cout<<">>>請輸入您的選擇:(0-2 )_"cin>>choice;cout<<""<<endl;switch(choice)case 1: Goods_Message_Manage(Goods,size); break;case 2:Goods_Sale(Goods,size);break;case 0: cout<<">>>>>>>&g
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 茂名職業(yè)技術(shù)學(xué)院《社會工作法規(guī)與政策》2023-2024學(xué)年第二學(xué)期期末試卷
- 銅仁學(xué)院《研學(xué)旅行培訓(xùn)》2023-2024學(xué)年第二學(xué)期期末試卷
- 成都藝術(shù)職業(yè)大學(xué)《云計算平臺技術(shù)》2023-2024學(xué)年第二學(xué)期期末試卷
- 浙江廣廈建設(shè)職業(yè)技術(shù)大學(xué)《魏碑臨摹》2023-2024學(xué)年第二學(xué)期期末試卷
- 燕京理工學(xué)院《教學(xué)理論與實踐》2023-2024學(xué)年第二學(xué)期期末試卷
- 西安城市建設(shè)職業(yè)學(xué)院《酒類生產(chǎn)工藝與產(chǎn)品質(zhì)量控制》2023-2024學(xué)年第二學(xué)期期末試卷
- 廣西工業(yè)職業(yè)技術(shù)學(xué)院《男生羽毛球》2023-2024學(xué)年第二學(xué)期期末試卷
- 大學(xué)生就業(yè)指導(dǎo)考核復(fù)習(xí)題庫58題含答案
- 江蘇財經(jīng)職業(yè)技術(shù)學(xué)院《地方公共政策學(xué)》2023-2024學(xué)年第二學(xué)期期末試卷
- 商洛職業(yè)技術(shù)學(xué)院《面向?qū)ο驝程序設(shè)計1》2023-2024學(xué)年第二學(xué)期期末試卷
- 移動式壓力容器充裝復(fù)審換證考試重點題庫(180題)
- 小班安全《湯姆走丟了》PPT課件教案反思微視頻
- 作物栽培學(xué)課件棉花
- 最新小學(xué)二年級口算及豎式計算練習(xí)題
- 生產(chǎn)與運作管理-陳榮秋
- 金雞冠的公雞繪本課件
- 日影朝向及長短
- 沙盤游戲治療(課堂PPT)
- (完整版)學(xué)生的自我評價的表格
- 樸素貝葉斯分類器完整
- 教育系統(tǒng)績效工資分配方案(共6頁)
評論
0/150
提交評論