久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 1495|回復: 1
打印 上一主題 下一主題
收起左側

c++商品銷售統計程序,有沒有大神給我看看呢

[復制鏈接]
跳轉到指定樓層
樓主
ID:426839 發表于 2018-11-15 08:55 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
c++源程序如下:
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <conio.h>
  4. #include<fstream>
  5. #define null 0
  6. #include<iostream>
  7. #include <iomanip>
  8. #include<string>     //控制字符串的頭文件
  9. using namespace std;
  10. class tong
  11. {
  12. public:
  13. tong();
  14. tong(char co[20],char n[20],
  15. char dw[20],double pr,int qu);
  16. ~tong();
  17. void save();
  18. void take();
  19. void Set();                         //商品信息錄入
  20. void Alter();                       //商品信息修改
  21. void list();                        //商品信息顯示
  22. void Display();
  23. float Checkout(int quantity);        //單個商品小結
  24. void Total();                        //總計
  25. void buy();                          //商品買入
  26. private :
  27. char code[20];char name[20];char danwei[20];double price;int quantity;
  28. };
  29. tong::tong(){}
  30. tong::tong(char co[20],char n[20],char dw[20],double pr,int qu){
  31. strcpy(code,co);
  32. strcpy(name,n);
  33. strcpy(danwei,dw);
  34. price=pr;
  35. quantity=qu;}
  36. tong::~tong(){}
  37. tong *s[50];
  38. int i=0;
  39. int j=0;
  40. char code[20];char name[20];char danwei[20];double price; int quantity;


  41. void tong::save() //寫入數據至文件
  42. {
  43. ofstream outfile;
  44. outfile.open("F:\\商品訂購\\商品訂購.txt",ios::out);
  45. if(!outfile)
  46. {
  47. cout<<"cannot open the file!"<<endl;
  48. return ;
  49. }
  50. else
  51. outfile<<"商品代碼及名稱"<<""<<"商品單價"<<""<<"請輸入商品數量"<<""<<"計量單位"<<endl;
  52. cout<<"商品代碼及名稱"<<""<<"商品單價"<<""<<"請輸入商品數量"<<""<<"計量單位"<<endl;
  53. for(int k=0;k<i;k++)
  54. {
  55. cout<<setw(10)<<left<<s[k]->code<<setw(10)<<left<<s[k]->name<<setw(15)<<left<<s[k]->price<<setw(10)<<left<<s[k]->quantity<<setw(15)<<left<<s[k]->danwei<<endl;
  56. outfile<<setw(10)<<left<<s[k]->code<<setw(10)<<left<<s[k]->name<<setw(15)<<left<<s[k]->price<<setw(10)<<left<<s[k]->quantity<<setw(15)<<left<<s[k]->danwei<<endl;
  57. }
  58. cout<<"**********************************Save Success!***************************************"<<endl;
  59. outfile.close();
  60. }

  61. void tong::Set()                   //商品信息錄入
  62. {
  63. cout<<"請輸入商品代碼及名稱:"<<endl;
  64. cin>>code>>name;
  65. cout<<"請輸入計量單位:"<<endl;
  66. cin>>danwei;
  67. cout<<"請輸入商品單價:"<<endl;
  68. cin>>price;
  69. cout<<"請輸入商品數量:"<<endl;
  70. cin>>quantity;
  71. j++;
  72. s[i]=new tong(code,name,danwei,price,quantity);   //沒有循環
  73. i++;
  74. cout<<"信息錄入成功!"<<endl;
  75. cout<<"是否繼續錄入?(y or n)"<<endl;
  76. if(getch()=='y')
  77. Set();
  78. else return;
  79. }

  80. void tong::Alter()//商品信息修改
  81. {
  82. cout<<"請輸入您所修改的商品名稱:"<<endl;
  83. cin>>name;
  84. for(int h=0;h<i;h++)
  85. if(strcmp(name,s[h]->name)==0)
  86. {
  87. char newcode[20];
  88. char newname[20];
  89. char newdanwei[20];
  90. double newprice;
  91. int newquantity;
  92. int n;
  93. cout<<"你想要修改:代碼及名稱按3) 、數量(請按4)"<<endl;
  94. cin>>n;
  95. switch(n)
  96. {
  97. case 1:
  98. { cout<<"請輸入商品代碼及名稱:"<<endl;
  99. cin>>newcode[20]>>newname[20];
  100. s[h]->code[20]=newcode[20];
  101. s[h]->name[20]=newname[20];
  102. cout<<"數據修改成功!";
  103. }break;
  104. case 2:            
  105.               {                       
  106.                             cout<<"請輸入計量單位:"<<endl;                       
  107.                             cin>>newdanwei;              
  108.                             s[h]->danwei[20]=newdanwei[20];                       
  109.                             cout<<"數據修改成功!";                  
  110.               }break;                    
  111. case 3:                    
  112.               {                       
  113.                             cout<<"請輸入單價:"<<endl;                       
  114.                             cin>>newprice;           
  115.                             s[h]->price=newprice;                       
  116.                             cout<<"數據修改成功!";                        
  117.               }break;
  118. case 4:
  119. {
  120. cout<<"請輸入數量:"<<endl;
  121. cin>>newquantity;
  122. s[h]->quantity=newquantity;
  123. cout<<"數據修改成功!";
  124. }break;
  125. }
  126. }
  127. else
  128. cout<<"你所要修改的商品的信息不存在,請修正后在更改!"<<endl;
  129. cout<<"是否繼續修改?(y/n)"<<endl;
  130. if(getch()=='y')
  131. Alter();
  132. else return ;
  133. }



  134. void tong::list()                  //商品信息顯示
  135. {
  136. cout<<"=========================================================="<<endl;
  137. cout<<"===================所有商品信息==================="<<endl;
  138. cout<<"=========================================================="<<endl;
  139. cout<<"貨品代碼=======貨品名稱======貨品價格======貨品數量======計量單位"<<endl;
  140. if(i==0)
  141. cout<<"系統中沒有錄入商品信息或該商品信息已被刪除!"<<endl;
  142. for(int k=0;k<i;k++){
  143. cout<<setw(15)<<left<<s[k]->code<<setw(15)<<left<<s[k]->name<<setw(15)<<left<<s[k]->price<<setw(15)<<left<<s[k]->quantity<<setw(15)<<left<<s[k]->danwei<<endl;
  144. }
  145. }


  146. void tong::buy()                       //商品買入
  147. {
  148. cout<<"請輸入你想購買的商品的代碼及名稱:"<<endl;
  149. cin>>code>>name;
  150. cout<<"請輸入您想購買的商品的數量:"<<endl;
  151. cin>>quantity;
  152. Checkout(quantity);
  153. Display();
  154. Total();
  155. }
  156. void tong::Display()
  157. {
  158. int k;
  159. k=atoi(code)-1;
  160. cout<<"貨品代碼=======貨品名稱======貨品價格======購買數量======計量單位=====小計(元)=="<<endl;
  161. cout<<setw(15)<<left<<s[k]->code
  162. <<setw(15)<<left<<s[k]->name
  163. <<setw(15)<<left<<s[k]->price
  164. <<setw(15)<<left<<quantity
  165. <<setw(15)<<left<<s[k]->danwei
  166. <<setw(15)<<left<<quantity*s[k]->price<<endl;
  167. }


  168. float tong::Checkout(int quantity)                    //單個商品小結
  169. {
  170. int k=0;
  171. float sum(0.0);
  172. sum=s[k]->price * quantity;
  173. return sum;
  174. }


  175. void tong::Total()                            //總結帳
  176. {
  177. float sum = 0;
  178. float factly;
  179. char GoOn;
  180. while(1)
  181. {
  182. cout<<"要結束商品買入請按'N/n',其繼續買入請按'Y/y': "<<endl;
  183. cin>>GoOn;
  184. if(GoOn=='Y'||GoOn=='y'){      //int quantity;
  185. cout<<"請輸入商品代碼:"<<endl;
  186. cin>>code>>name;
  187. cout<<"請輸入商品數量:"<<endl;
  188. cin>>quantity;
  189. sum+=Checkout(quantity);
  190. cout<<"你購買的商品為:"<<endl;
  191. Display();
  192. }
  193. else if(GoOn=='N'||GoOn=='n')
  194. break;
  195. }
  196. cout<<"----------------------------------------------------"<<endl;
  197. sum+=Checkout(quantity);
  198. cout<<"你應該付 "<<sum<<"元!"<<endl;
  199. cout<<"你實際付(元): ";
  200. cin>>factly;
  201. cout<<"應該找回你 "<<factly-sum<<"元!"<<endl;     //找零。
  202. }


  203. void caozuoa(int p){
  204. tong t;
  205. switch(p){
  206. case 0:t.Set();break;
  207. case 1:t. Alter ();break;
  208. case 2:t.save();break;
  209. case 8:exit(0);break;
  210. }
  211. }
  212. void caozuob(int p){
  213. tong t;
  214. switch(p){
  215. case 0:t.list();break;
  216. case 1:t.buy();break;
  217. case 8:exit(0);break;
  218. }
  219. }
  220. void main()
  221. {
  222. int a;
  223. char w;
  224. cout<<"*-------------------------------------------------*"<<endl;
  225. cout<<"***************************************************"<<endl;     
  226. cout<<"\n"<<endl;
  227. cout<<"*------------歡迎進入商品訂購統計系統-------------*"<<endl;         
  228. cout<<"\n"<<endl;
  229. cout<<"***************************************************"<<endl;   
  230. do{
  231. cout<<"請選擇您的操作:商品信息管理系統(M)商品訂購系統(S)"<<endl;         
  232. cin>>w;
  233. cout<<"*---------------------菜單選項--------------------*"<<endl;
  234. cout<<"*-------------------------------------------------*"<<endl;
  235. cout<<"*-------------------------------------------------*"<<endl;
  236. cout<<"\n"<<endl;
  237. if(w=='M'||w=='m')
  238. {  cout<<"商品信息錄入(請輸入0) 修改信息(請輸入1) 保存信息(請輸入2) "<<endl;
  239. cin>>a;               
  240. caozuoa(a);               
  241. }        
  242. else if(w=='S'||w=='s')
  243. {           
  244.               cout<<"顯示商品信息(請輸入0)   商品買入(請輸入1)  "<<endl;            
  245.               cin>>a;                 
  246.               caozuob(a);               
  247. }               
  248. else
  249. {               
  250.               cout<<"請輸入'M' 、'm' 或'S' 、's'"<<endl;}               
  251. cout<<"您想繼續進行其他操作嗎?(y/n)"<<endl;                 
  252. cin>>w;  
  253. }
  254. while(w=='y');
  255. }
復制代碼


分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

沙發
ID:1 發表于 2018-11-15 16:23 | 只看該作者
您這個問題給的信息不全,估計是沒人能回答得了的,先轉移到冷門區了,自行編輯補充一下吧,審核員會幫你重新轉到熱門問答區的
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 成人av色 | 久久51 | 一级毛片视频 | 在线一区观看 | 在线免费观看黄a | 日韩久久久久久久久久久 | 国产精品久久久久久吹潮 | 日韩a| 最新中文字幕在线 | 欧美成年人 | 一区二区三区在线观看视频 | 看真人视频一级毛片 | 国产精品久久九九 | 日本在线中文 | 日韩一区二区三区精品 | 精品日韩 | 亚洲精品一区中文字幕乱码 | 亚洲色欲色欲www | 毛片av免费在线观看 | a级黄色毛片免费播放视频 国产精品视频在线观看 | 久久一区二区三区四区五区 | 91手机精品视频 | 欧美a级成人淫片免费看 | 91看片免费版 | 精品国产视频 | 精品一区免费 | 精品自拍视频在线观看 | 精品国产一区久久 | 正在播放国产精品 | 99久久99热这里只有精品 | 夜夜草 | 精品中文字幕视频 | 国产精品黄| 暴草美女| 亚洲欧美日韩系列 | 一级片视频免费 | 草草在线观看 | 一级毛片免费看 | 日韩欧美在线视频观看 | 91在线视频一区 | 秋霞在线一区二区 |