Board logo

標題: [隨堂測驗] 購物系統 (三) [打印本頁]

作者: 方浩葦    時間: 2024-7-13 09:09     標題: [隨堂測驗] 購物系統 (三)

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



本帖隱藏的內容需要回復才可以瀏覽

作者: 林少謙    時間: 2024-7-13 16:28

本帖最後由 林少謙 於 2024-7-13 20:47 編輯
  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     system("cls");
  8.     string a[]{"遙控汽車","飛機模型","足球    ","拼圖    ","玩具槍  ","可愛玩偶","籃球    ",};
  9.     int b[]={450,550,325,200,660,150,380};
  10.     int c[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  11.     int d[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

  12.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  13.     cout<<"商品價目表"<<endl;
  14.     for(int i=0; i<7;  i++)
  15.     {
  16.         cout<<"<"<<i+1<<">"<<a[i]<<"\t"<<b[i]<<"元"<<endl;
  17.     }
  18.     cout<<"<8>結帳"<<endl;
  19.     cout<<endl;
  20.     int x,y,z=-1,w=-1,sum=0;
  21.     re2:
  22.     cout<<"請輸入商品代碼:";
  23.     cin>>x;
  24.     if(x==8)
  25.     {
  26.         goto out;
  27.     }
  28.     else if(x>=1&&x<=7)
  29.     {
  30.         cout<<"請輸入購買數量:";
  31.         cin>>y;
  32.         z++;
  33.         sum+=b[x-1]*y;
  34.         c[z]+=y;
  35.         d[z]+=x;
  36.         goto re2;
  37.     }
  38.     else
  39.     {
  40.         cout<<"輸入錯誤"<<endl;
  41.         goto re2;
  42.     }
  43.     out:
  44.     cout<<endl;
  45.     cout<<"[購物清單]"<<endl;
  46.     cout<<"------------------------"<<endl;
  47.     for(int i=0 ; i<=30 ;i++)
  48.     {
  49.         if(d[i]!=0)
  50.         {
  51.             cout<<a[d[i]-1]<<"\t"<<b[d[i]-1]<<"元*"<<c[i]<<"個"<<endl;
  52.         }
  53.     }
  54.     cout<<"------------------------"<<endl;
  55.     cout<<endl<<"總共"<<sum<<"元!"<<endl;

  56.     system("pause");
  57.     goto re;
  58.     return 0;
  59. }
複製代碼

作者: 高湘庭    時間: 2024-7-14 20:01

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main(){
  5. while(true){
  6. system("cls");
  7. int p,q, sum = 0;
  8. int t[7]={0};
  9. string name[]={"遙控汽車","飛機模型","足球    ","拼圖    ","玩具槍  ","可愛玩偶","籃球    "};
  10. int price[]={450,550,325,200,660,150,380};
  11. cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  12. cout<<"[商品價目表]"<<endl;
  13. for(int i=0;i<7;i++){
  14. cout<<"<"<<i+1<<">"<<name[i]<<"\t"<<price[i]<<"元"<<endl;}
  15. cout<<"<8>"<<"結帳"<<endl;



  16. while(true){
  17. cout<<"請輸入商品代碼"<<endl;
  18. cin>>p;
  19.   if(p==8)
  20. break;
  21. else if(p>=1&&p<=7){
  22. cout<<"數量:";
  23. cin>>q;
  24. sum+=price[p-1]*q;
  25. t[p-1]+=q;
  26. }
  27. else{
  28. cout<<"無效的商品代碼,請重新輸入"<<endl;
  29. }

  30. }

  31. cout<<"=================="<<endl;
  32. cout<<"[購物清單]"<<endl;
  33. for(int i=0;i<7;i++){
  34.     if(t[i]>0)
  35. cout<<name[i]<<"\t\t"<<price[i]<<"*"<<t[i]<<"個"<<endl;

  36. }
  37. cout<<"===================="<<endl;


  38. cout<<endl<<"總共"<<sum<<"元!"<<endl;
  39.     system("pause");
  40. }



  41. return 0;
  42. }
複製代碼

作者: 陳妍蓁    時間: 2024-7-20 14:26

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main(){
  5. re:
  6.     system("cls");
  7.     int x,y,sum=0;
  8.     int t[7]={0};
  9.     string n[7]={"遙控汽車","飛機模型","足球  ","拼圖  ","玩具槍 ","可愛玩偶","籃球  "};
  10.     int p[7]={450,550,325,200,660,150,380};

  11.     cout<<"***智能玩具店***"<<endl;
  12.     cout<<"[價目表]"<<endl;
  13.     for(int i=0;i<7;i++)
  14.         cout<<"("<<i+1<<")"<<n[i]<<"\t"<<p[i]<<"元"<<endl;
  15.     cout<<"(8)結帳"<<endl;
  16. re2:
  17.     cout<<"請輸入商品代號: "<<endl;
  18.     cin>>x;
  19.     if(x==8)
  20.         goto checkout;
  21.     else if(x>=1&&x<=7){
  22.         cout<<"輸入數量"<<endl;
  23.         cin>>y;
  24.         sum+=p[x-1]*y;
  25.         t[x-1]=t[x-1]+y;
  26.         goto re2;
  27.     }
  28.     else
  29.         goto re;
  30.     checkout:
  31.         cout<<"[購物清單]"<<endl;
  32.         cout<<"--------------------------------"<<endl;
  33.         for(int i=0;i<7;i++){
  34.             if(t[i]>0)
  35.             cout<<n[i]<<"\t"<<p[i]<<"元*"<<t[i]<<endl;
  36.         }
  37.         cout<<"--------------------------------"<<endl;
  38.         cout<<"總共"<<sum<<"元"<<endl;

  39. system("pause");
  40. goto re;
  41. return 0;

  42. }
複製代碼

作者: 劉奕劭    時間: 2024-7-20 14:38

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     system("cls");
  8.     int p,q,r=0;
  9.     int z=0;
  10.     string a[]={"遙控汽車","飛機模型","足球    ","拼圖    ","玩具槍  ","可愛玩偶","籃球    "};
  11.     int b[]={450,550,325,200,660,150,380};
  12.     int c[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  13.     int d[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

  14.     cout<<"智能玩具店"<<endl;
  15.     cout<<endl;
  16.     cout<<"[商品價目表]"<<endl;
  17.     for(int i=0; i<=6; i++)
  18.         cout<<"("<<i+1<<")"<<a[i]<<"\t"<<b[i]<<"元"<<endl;
  19.     cout<<"(8)"<<"結帳"<<endl;
  20.     re2:
  21.     cout<<"請輸入商品代碼:";
  22.     cin>>p;
  23.     if(p==8){

  24.         goto checkout;

  25.     }
  26.     else if(p<=7&&p>=1){

  27.         cout<<"數量: ";
  28.         cin>>q;

  29.         r+=b[p-1]*q;
  30.         c[z]=p;
  31.         d[z]=q;
  32.         z++;
  33.         goto re2;
  34.     }
  35.     else{

  36.         cout<<"輸入錯誤"<<endl;
  37.         goto re2;

  38.     }

  39.     checkout:
  40.     cout<<"[購物清單]"<<endl;
  41.     for(int i=0;i<=z;i++){
  42.     if(z>1){
  43.     cout<<a[c[i]-1]<<"\t\t"<<b[c[i]-1]<<"*"<<d[i]<<"個"<<endl;
  44.         }

  45.     }
  46.     cout<<"===================="<<endl;

  47.     cout<<"總共"<<r<<"元!"<<endl;

  48.     system("pause");
  49.     goto re;
  50.     return 0;
  51. }
複製代碼

作者: 洪榮辰    時間: 2024-7-20 14:51

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     system("cls");
  8.     int x, y, sum=0;
  9.     int t[7]={0};
  10.     string name[]={"遙控汽車","飛機模型","足球    ","拼圖    ","玩具槍  ","可愛玩偶","籃球    "};
  11.     int price[]={450,550,325,200,660,150,380};
  12.     cout<<"***智能玩具店***"<<endl<<endl;
  13.     cout<<"[商品價目表]"<<endl;
  14.     for(int i=0; i<7; i++)
  15.         cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
  16.     cout<<"(8)結帳"<<endl<<endl;
  17.     re2:
  18.     cout<<"請輸入商品代碼: ";
  19.     cin>>x;
  20.     if(x==8)
  21.     {
  22.         cout<<endl;
  23.         goto checkout;
  24.     }
  25.     else if(x>=1 && x<=7)
  26.     {
  27.         cout<<"數量: ";
  28.         cin>>y;
  29.         sum+=price[x-1]*y;
  30.         t[x-1]=t[x-1]+y;
  31.         goto re2;
  32.     }
  33.     checkout:
  34.     cout<<"[購物清單]"<<endl;
  35.     cout<<"============================"<<endl;
  36.     for(int i=0; i<7; i++)
  37.     {
  38.         if(t[i]>0)
  39.         cout<<name[i]<<"\t"<<price[i]<<"元"<<" x "<<t[i]<<"個"<<endl;
  40.     }
  41.     cout<<"============================"<<endl;
  42.     cout<<"總共"<<sum<<"元!"<<endl;
  43.     system("pause");
  44.     goto re;
  45.     return 0;
  46. }
複製代碼

作者: 李唯銘    時間: 2024-7-26 15:31

  1. #include<iostream>
  2. #include<cstdlib>
  3. using namespace std;
  4. int main()
  5. {
  6.     re:
  7.     system("cls");
  8.     string a[]{"遙控汽車","飛機模型","足球    ","拼圖    ","玩具槍  ","可愛玩偶","籃球    ",};
  9.     int b[]={450,550,325,200,660,150,380};
  10.     int c[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
  11.     int d[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

  12.     cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
  13.     cout<<"商品價目表"<<endl;
  14.     for(int i=0; i<7;  i++)
  15.     {
  16.         cout<<"<"<<i+1<<">"<<a[i]<<"\t"<<b[i]<<"元"<<endl;
  17.     }
  18.     cout<<"<8>結帳"<<endl;
  19.     cout<<endl;
  20.     int x,y,z=-1,w=-1,sum=0;
  21.     re2:
  22.     cout<<"請輸入商品代碼:";
  23.     cin>>x;
  24.     if(x==8)
  25.     {
  26.         goto out;
  27.     }
  28.     else if(x>=1&&x<=7)
  29.     {
  30.         cout<<"請輸入購買數量:";
  31.         cin>>y;
  32.         z++;
  33.         sum+=b[x-1]*y;
  34.         c[z]+=y;
  35.         d[z]+=x;
  36.         goto re2;
  37.     }
  38.     else
  39.     {
  40.         cout<<"輸入錯誤"<<endl;
  41.         goto re2;
  42.     }
  43.     out:
  44.     cout<<endl;
  45.     cout<<"[購物清單]"<<endl;
  46.     cout<<"------------------------"<<endl;
  47.     for(int i=0 ; i<=30 ;i++)
  48.     {
  49.         if(d[i]!=0)
  50.         {
  51.             cout<<a[d[i]-1]<<"\t"<<b[d[i]-1]<<"元*"<<c[i]<<"個"<<endl;
  52.         }
  53.     }
  54.     cout<<"------------------------"<<endl;
  55.     cout<<endl<<"總共"<<sum<<"元!"<<endl;

  56.     system("pause");
  57.     goto re;
  58.     return 0;
  59. }
複製代碼





歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/) Powered by Discuz! 7.2