標題:
[隨堂測驗] 購物系統 (三)
[打印本頁]
作者:
方浩葦
時間:
2024-7-13 09:09
標題:
[隨堂測驗] 購物系統 (三)
新增 "購物清單" 功能,使結帳時能不只計算出價錢,還能列出細目。
參考執行畫面如下:
本帖隱藏的內容需要回復才可以瀏覽
作者:
林少謙
時間:
2024-7-13 16:28
本帖最後由 林少謙 於 2024-7-13 20:47 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
string a[]{"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 ",};
int b[]={450,550,325,200,660,150,380};
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};
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};
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"商品價目表"<<endl;
for(int i=0; i<7; i++)
{
cout<<"<"<<i+1<<">"<<a[i]<<"\t"<<b[i]<<"元"<<endl;
}
cout<<"<8>結帳"<<endl;
cout<<endl;
int x,y,z=-1,w=-1,sum=0;
re2:
cout<<"請輸入商品代碼:";
cin>>x;
if(x==8)
{
goto out;
}
else if(x>=1&&x<=7)
{
cout<<"請輸入購買數量:";
cin>>y;
z++;
sum+=b[x-1]*y;
c[z]+=y;
d[z]+=x;
goto re2;
}
else
{
cout<<"輸入錯誤"<<endl;
goto re2;
}
out:
cout<<endl;
cout<<"[購物清單]"<<endl;
cout<<"------------------------"<<endl;
for(int i=0 ; i<=30 ;i++)
{
if(d[i]!=0)
{
cout<<a[d[i]-1]<<"\t"<<b[d[i]-1]<<"元*"<<c[i]<<"個"<<endl;
}
}
cout<<"------------------------"<<endl;
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
高湘庭
時間:
2024-7-14 20:01
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
while(true){
system("cls");
int p,q, sum = 0;
int t[7]={0};
string name[]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int price[]={450,550,325,200,660,150,380};
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0;i<7;i++){
cout<<"<"<<i+1<<">"<<name[i]<<"\t"<<price[i]<<"元"<<endl;}
cout<<"<8>"<<"結帳"<<endl;
while(true){
cout<<"請輸入商品代碼"<<endl;
cin>>p;
if(p==8)
break;
else if(p>=1&&p<=7){
cout<<"數量:";
cin>>q;
sum+=price[p-1]*q;
t[p-1]+=q;
}
else{
cout<<"無效的商品代碼,請重新輸入"<<endl;
}
}
cout<<"=================="<<endl;
cout<<"[購物清單]"<<endl;
for(int i=0;i<7;i++){
if(t[i]>0)
cout<<name[i]<<"\t\t"<<price[i]<<"*"<<t[i]<<"個"<<endl;
}
cout<<"===================="<<endl;
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
}
return 0;
}
複製代碼
作者:
陳妍蓁
時間:
2024-7-20 14:26
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
re:
system("cls");
int x,y,sum=0;
int t[7]={0};
string n[7]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int p[7]={450,550,325,200,660,150,380};
cout<<"***智能玩具店***"<<endl;
cout<<"[價目表]"<<endl;
for(int i=0;i<7;i++)
cout<<"("<<i+1<<")"<<n[i]<<"\t"<<p[i]<<"元"<<endl;
cout<<"(8)結帳"<<endl;
re2:
cout<<"請輸入商品代號: "<<endl;
cin>>x;
if(x==8)
goto checkout;
else if(x>=1&&x<=7){
cout<<"輸入數量"<<endl;
cin>>y;
sum+=p[x-1]*y;
t[x-1]=t[x-1]+y;
goto re2;
}
else
goto re;
checkout:
cout<<"[購物清單]"<<endl;
cout<<"--------------------------------"<<endl;
for(int i=0;i<7;i++){
if(t[i]>0)
cout<<n[i]<<"\t"<<p[i]<<"元*"<<t[i]<<endl;
}
cout<<"--------------------------------"<<endl;
cout<<"總共"<<sum<<"元"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
劉奕劭
時間:
2024-7-20 14:38
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int p,q,r=0;
int z=0;
string a[]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int b[]={450,550,325,200,660,150,380};
int c[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int d[]={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
cout<<"智能玩具店"<<endl;
cout<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0; i<=6; i++)
cout<<"("<<i+1<<")"<<a[i]<<"\t"<<b[i]<<"元"<<endl;
cout<<"(8)"<<"結帳"<<endl;
re2:
cout<<"請輸入商品代碼:";
cin>>p;
if(p==8){
goto checkout;
}
else if(p<=7&&p>=1){
cout<<"數量: ";
cin>>q;
r+=b[p-1]*q;
c[z]=p;
d[z]=q;
z++;
goto re2;
}
else{
cout<<"輸入錯誤"<<endl;
goto re2;
}
checkout:
cout<<"[購物清單]"<<endl;
for(int i=0;i<=z;i++){
if(z>1){
cout<<a[c[i]-1]<<"\t\t"<<b[c[i]-1]<<"*"<<d[i]<<"個"<<endl;
}
}
cout<<"===================="<<endl;
cout<<"總共"<<r<<"元!"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
洪榮辰
時間:
2024-7-20 14:51
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
int x, y, sum=0;
int t[7]={0};
string name[]={"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 "};
int price[]={450,550,325,200,660,150,380};
cout<<"***智能玩具店***"<<endl<<endl;
cout<<"[商品價目表]"<<endl;
for(int i=0; i<7; i++)
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<price[i]<<"元"<<endl;
cout<<"(8)結帳"<<endl<<endl;
re2:
cout<<"請輸入商品代碼: ";
cin>>x;
if(x==8)
{
cout<<endl;
goto checkout;
}
else if(x>=1 && x<=7)
{
cout<<"數量: ";
cin>>y;
sum+=price[x-1]*y;
t[x-1]=t[x-1]+y;
goto re2;
}
checkout:
cout<<"[購物清單]"<<endl;
cout<<"============================"<<endl;
for(int i=0; i<7; i++)
{
if(t[i]>0)
cout<<name[i]<<"\t"<<price[i]<<"元"<<" x "<<t[i]<<"個"<<endl;
}
cout<<"============================"<<endl;
cout<<"總共"<<sum<<"元!"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
作者:
李唯銘
時間:
2024-7-26 15:31
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
re:
system("cls");
string a[]{"遙控汽車","飛機模型","足球 ","拼圖 ","玩具槍 ","可愛玩偶","籃球 ",};
int b[]={450,550,325,200,660,150,380};
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};
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};
cout<<"☆★☆智能玩具店☆★☆"<<endl<<endl;
cout<<"商品價目表"<<endl;
for(int i=0; i<7; i++)
{
cout<<"<"<<i+1<<">"<<a[i]<<"\t"<<b[i]<<"元"<<endl;
}
cout<<"<8>結帳"<<endl;
cout<<endl;
int x,y,z=-1,w=-1,sum=0;
re2:
cout<<"請輸入商品代碼:";
cin>>x;
if(x==8)
{
goto out;
}
else if(x>=1&&x<=7)
{
cout<<"請輸入購買數量:";
cin>>y;
z++;
sum+=b[x-1]*y;
c[z]+=y;
d[z]+=x;
goto re2;
}
else
{
cout<<"輸入錯誤"<<endl;
goto re2;
}
out:
cout<<endl;
cout<<"[購物清單]"<<endl;
cout<<"------------------------"<<endl;
for(int i=0 ; i<=30 ;i++)
{
if(d[i]!=0)
{
cout<<a[d[i]-1]<<"\t"<<b[d[i]-1]<<"元*"<<c[i]<<"個"<<endl;
}
}
cout<<"------------------------"<<endl;
cout<<endl<<"總共"<<sum<<"元!"<<endl;
system("pause");
goto re;
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2