欧美极品高清xxxxhd,国产日产欧美最新,无码AV国产东京热AV无码,国产精品人与动性XXX,国产传媒亚洲综合一区二区,四库影院永久国产精品,毛片免费免费高清视频,福利所导航夜趣136

標題: c++商品銷售統計程序,有沒有大神給我看看呢 [打印本頁]

作者: NickChen520    時間: 2018-11-15 08:55
標題: c++商品銷售統計程序,有沒有大神給我看看呢
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. }
復制代碼



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




歡迎光臨 (http://m.raoushi.com/bbs/) Powered by Discuz! X3.1