返回列表 發帖

購物系統 (三)

本帖最後由 tonyh 於 2015-3-21 11:41 編輯

新增 "購物清單" 功能, 使結帳時能不只計算出價錢, 還能列出細目.
參考執行畫面如下:

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int p,q,sum=0;
  7.     string name[7]={"遙控汽車","飛機模型","足球    ",
  8.                     "拼圖    ","玩具槍  ","可愛玩偶","籃球    "};
  9.     int price[7]={450,550,325,200,660,150,380};
  10.     int qty[7]={0,0,0,0,0,0,0};
  11.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  12.     cout<<"[商品價目表]"<<endl;
  13.     for(int i=0; i<7; i++)
  14.     {
  15.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
  16.     }
  17.     cout<<"(8)結帳"<<endl<<endl;
  18.     re:
  19.     cout<<"請輸入商品代碼: ";
  20.     cin>>p;
  21.     if(p==8)
  22.         goto checkout;
  23.     else if(p>=1 && p<=7)
  24.     {
  25.         cout<<"數量: ";
  26.         cin>>q;
  27.         if(q<=0)
  28.         {
  29.             cout<<"輸入錯誤!"<<endl;
  30.             goto re;        
  31.         }
  32.         sum+=price[p-1]*q;
  33.         qty[p-1]+=q;         
  34.     }
  35.     else
  36.     {
  37.         cout<<"輸入錯誤!"<<endl;   
  38.     }
  39.     goto re;
  40.     checkout:
  41.     cout<<endl<<"[購物清單]"<<endl;         
  42.     cout<<"-----------------------------"<<endl;
  43.     for(int i=0; i<7; i++)
  44.     {
  45.         if(qty[i]!=0)
  46.             cout<<name[i]<<"\t"<<price[i]<<"元 * "<<qty[i]<<"個"<<endl;  
  47.     }
  48.     cout<<"-----------------------------"<<endl;         
  49.     cout<<"總共"<<sum<<"元!"<<endl<<endl;
  50.     system("pause");
  51.     return 0;   
  52. }
複製代碼
附件: 您需要登錄才可以下載或查看附件。沒有帳號?註冊

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int p,q,sum=0;
  7.     string name[5]={"CAD   ","NERvGear","蘿球   ","密斯提斯","吉太    "};
  8.     int price[5]={10000,20000,20000,10000,10000};
  9.     cout<<"<?<?<?<<動漫道具店>>?>?>?>"<<endl;
  10.     cout<<"<?<?<?<<商品價目表>>?>?>?>"<<endl;
  11.     for(int i=0; i<5; i++)
  12.     {
  13.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
  14.     }  
  15.     cout<<"(6)結帳"<<endl<<endl;
  16.     re:
  17.     cout<<"請輸入商品代碼: ";
  18.     cin>>p;
  19.     if(p==6)
  20.     goto checkout;
  21.     else if(p>=1 && p<=5)
  22.     {
  23.         cout<<"數量: ";
  24.         cin>>q;
  25.         if(q<=0)
  26.         {
  27.             cout<<"輸入錯誤!"<<endl;
  28.             goto re;        
  29.         }
  30.         sum+=price[p-1]*q;     
  31.     }
  32.     else
  33.     {
  34.         cout<<"輸入錯誤!"<<endl;   
  35.     }
  36.     checkout:
  37.     qty[p-1]+=q;
  38.     cout<<"---------------------"<<endl;
  39.     for(int i=0;i<7;i++)
  40.     {
  41.          if(qty[i]>0)
  42.          cout<<name[i]<<"\t"<<price[i]<<"元"<<qty[i]<<"個"<<endl;
  43.     }
  44.     cout<<"---------------------"<<endl;
  45.     goto re;
  46.     cheakout;
  47.     cout<<endl<<"總共"<<sum<<"元!"<<endl;
  48.     system("pause");
  49.     return 0;   
  50. }
複製代碼
http://fs-old.mis.kuas.edu.tw/~s1102137106/music/

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int thing, number,sum=0;
  7.     string name[21]={"V家七宗罪系列(包含序號2~9)",
  8.                      "湯匙(齒輪)                ",
  9.                      "酒杯                      ",
  10.                      "劍                        ",
  11.                      "金鑰匙                    ",
  12.                      "人偶                      ",
  13.                      "四面鏡                    ",
  14.                      "禍世之剪                  ",
  15.                      "上了發條的搖籃曲          ",
  16.                      "白癡藥水                  ",
  17.                      "生鏽的齒輪人偶            ",
  18.                      "受詛咒之雙刃(附皮革套)    ",
  19.                      "跳針的古老大鐘            ",
  20.                      "失憶藥丸                  ",
  21.                      "座敷童子的靈棺            ",
  22.                      "淌血的附喪神人偶          ",
  23.                      "會咬人的蜘蛛玩偶          ",
  24.                      "梅杜莎的頭顱              ",
  25.                      "巫婆熬藥的大鍋            ",
  26.                      "活生生殭屍殺人魔/吸血鬼   "};
  27.     long money[21]={1200,70,80,80,100,120,150,100,350,
  28.                     70,80,20,1300,130,700,130,120,500,1000,10000};
  29.     int qty[21]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  30.     cout<<"XXX崩壞/中二玩具精品店XXX"<<endl;
  31.     cout<<"這裡的壞掉商品包山包海,應有盡有,等你來搜刮!"<<endl;
  32.     cout<<"本店絕對沒有惡意哄抬價格,也絕對沒有低價購入,高價賣出的不良嗜好,敬請安心"<<endl;
  33.     cout<<"對於購買商品的問題,出事本店一概不負責"<<endl;
  34.     cout<<"--------------------------------------------------------------------------"<<endl;
  35.     int i=0;
  36.     while(i<20)
  37.     {
  38.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<money[i]<<"萬元"<<endl;   
  39.         i++;
  40.     }
  41.     cout<<"(21)結帳"<<endl;
  42.     re:
  43.     cout<<"請輸入商品代號: "<<endl;
  44.     cin>>thing;
  45.     if(thing==21)
  46.     {
  47.         goto checkout;            
  48.     }
  49.     else if(thing>0 && thing<21)
  50.     {
  51.         cout<<"數量: "<<endl;
  52.         cin>>number;
  53.         if(number<=0)
  54.         {
  55.             cout<<"奧客去死辣!本店將會詛咒你的餘生(甩門)"<<endl;
  56.             goto re;        
  57.         }
  58.         sum+=money[thing-1]*number;
  59.         qty[thing-1]+=number;
  60.     }
  61.     else
  62.     {
  63.         cout<<"奧客去死辣!本店將會詛咒你的餘生(甩門)"<<endl;   
  64.     }
  65.     goto re;
  66.     checkout:
  67.     cout<<endl<<"中二精品購物清單"<<"\a"<<endl;
  68.     cout<<"------------------------------"<<"\n";
  69.     for(int i=0;i<21;i++)
  70.     {
  71.         if(qty[i]!=0)
  72.         {
  73.             cout<<name[i]<<"\t"<<money[i]<<"元 * "<<qty[i]<<"個"<<endl;           
  74.         }   
  75.     }
  76.     cout<<"------------------------------"<<"\n";
  77.     cout<<"共"<<sum<<"萬元"<<endl;
  78.     system("pause");
  79.     return 0;   
  80. }
複製代碼

TOP

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int p,q,sum=0;
  7.     string name[5]={"砍頭優惠卷","特效搖頭丸","自殺體驗卷","被打免費票","舒柔鼻涕蟲",};
  8.     int price[5]={99111,458645,14000,99999,100000};
  9.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  10.     cout<<"[商品價目表]"<<endl;
  11.     int qty[5]={0,0,0,0,0};
  12.     for(int i=0; i<5; i++)
  13.     {
  14.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
  15.     }
  16.     cout<<"(8)結帳"<<endl<<endl;
  17.     re:
  18.     cout<<"請輸入商品代碼: ";
  19.     cin>>p;
  20.     if(p==8)
  21.         goto checkout;
  22.     else if(p>=1 && p<=7)
  23.     {
  24.         cout<<"數量: ";
  25.         cin>>q;
  26.         if(q<=0)
  27.         {
  28.             cout<<"輸入錯誤!"<<endl;
  29.             goto re;        
  30.         }
  31.         sum+=price[p-1]*q;
  32.         qty[p-1]+=q;     
  33.     }
  34.     else
  35.     {
  36.         cout<<"輸入錯誤!"<<endl;   
  37.     }
  38.     goto re;
  39.     checkout:   
  40.     cout<<endl<<"噁心清單"<<endl;
  41.     cout<<"----------------------------------"<<endl;
  42.     for (int i=0;i<5;i++)
  43.     {
  44.         if(qty[i]!=0)
  45.             cout<<name[i]<<"\t"<<price[i]<<"元  *  "<<qty[i]<<"個"<<endl;        
  46.     }   
  47.     cout<<"----------------------------------"<<endl;
  48.     cout<<"總共"<<sum<<"元!"<<endl<<endl;   
  49.     system("pause");
  50.     return 0;   
  51. }
複製代碼

TOP

本帖最後由 洪振庭 於 2015-3-22 11:43 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     int p,q,sum=0;
  7.     string name[7]={"速效跳課糖","米你毛毛球","無頭帽","金斯雀奶油","攜帶型沼澤","假魔杖","伸縮耳"};
  8.     int price[7]={90,150,74,3,80,1,4};
  9.     int qty[7]={0,0,0,0,0,0,0};
  10.     cout<<"****衛氏巫師法寶店****"<<endl;
  11.     cout<<"<=商品價目表=>"<<endl;
  12.     for(int i=0; i<7; i++)
  13.     {
  14.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"金加隆"<<endl;
  15.     }  
  16.        cout<<"(8)結帳"<<endl<<endl;
  17.     re:
  18.     cout<<"請輸入商品代碼: ";
  19.     cin>>p;
  20.     if(p==8)
  21.         goto checkout;
  22.     else if(p>=1 && p<=7)
  23.     {
  24.         cout<<"數量: ";
  25.         cin>>q;
  26.         if(q<=0)
  27.         {
  28.             cout<<"輸入錯誤!"<<endl;
  29.             goto re;        
  30.         }
  31.         sum+=price[p-1]*q;
  32.         qty[p-1]+=q;         
  33.     }
  34.     else
  35.     {
  36.         cout<<"輸入錯誤!"<<endl;   
  37.     }
  38.     goto re;
  39.     checkout:
  40.     cout<<endl<<"[魔法清單]"<<endl;         
  41.     cout<<"-----------------------------"<<endl;
  42.     for(int i=0; i<7; i++)
  43.     {
  44.         if(qty[i]!=0)
  45.             cout<<name[i]<<"\t"<<price[i]<<"加隆 * "<<qty[i]<<"個"<<endl;  
  46.     }
  47.    
  48.     system("pause");
  49.     return 0;   

  50. }
複製代碼

TOP

返回列表