標題:
[作業]購物系統 (三)
[打印本頁]
作者:
張翼安
時間:
2016-3-18 22:11
標題:
[作業]購物系統 (三)
本帖最後由 張翼安 於 2016-4-23 12:07 編輯
新增 "購物清單" 功能, 使結帳時能不只計算出價錢, 還能列出細目.
參考執行畫面如下:
作者:
蔡季樺
時間:
2016-4-20 15:12
本帖最後由 蔡季樺 於 2016-4-26 17:46 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
string name[8]={"火焰藥水","放屁藥水","作夢藥水","打呵欠藥水","超人藥水","打老師藥水","萬能藥水","結帳"};
int inventory[7]={0,0,0,0,0,0,0};
int money[7]={200,50,100,10,2000,1100,1000000};
int commodity,quantity,checkout=0;
cout<<"~~★☆★沒路用的藥水專賣店☆★☆~~"<<endl;
cout<<"[價目表]"<<endl;
for(int i=0; i<=6; i++)
{
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<money[i]<<"元"<<endl;
}
cout<<"("<<"8"<<")"<<name[7]<<endl;
while(true)
{
cout<<"請輸入想要買的商品代碼(結帳按8):";
cin>>commodity;
if(commodity<1 || commodity>8)
continue;
if(commodity==8)
break;
cout<<"請輸入要買的數量:";
cin>>quantity;
inventory[commodity-1]+=quantity;
checkout+=quantity*money[commodity-1];
}
cout<<"〔購物清單〕"<<endl;
cout<<"-----------------------------------"<<endl;
for(int i=0;i<=6;i++)
{
if(inventory[i]!=0)
{
cout<<name[i]<<"\t";
cout<<money[i]<<"\t元 * ";
cout<<inventory[i]<<endl;
}
}
if(checkout==0)
cout<<"\t(空白)"<<endl;
cout<<"-----------------------------------"<<endl;
cout<<"總共要付"<<checkout<<"元!"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
張文擇
時間:
2016-4-23 17:24
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
string name[8]={"windows 10","windows 7","windows 8","windows 8.1","windows XP","windows 10","office 全部版本","結帳"};
int inventory[7]={0,0,0,0,0,0,0};
int money[7]={2000,5000,1000,10000,20,1150,1022225};
int commodity,quantity,checkout=0;
cout<<"微軟專賣店"<<endl;
cout<<"[價目表]"<<endl;
for(int i=0; i<=6; i++)
{
cout<<"("<<i+1<<")"<<name[i]<<"\t"<<money[i]<<"元"<<endl;
}
cout<<"("<<"8"<<")"<<name[7]<<endl;
while(commodity!=8)
{
cout<<"請輸入想要買的商品號碼(結帳請按8):";
cin>>commodity;
if(commodity==8)
break;
cout<<"請輸入要購的數量:";
cin>>quantity;
inventory[commodity-1]+=quantity;
checkout+=quantity*money[commodity-1];
}
cout<<"買物清單"<<endl;
cout<<"-----------------------------------"<<endl;
for(int i=0;i<=6;i++)
{
if(inventory[i]!=0)
{
cout<<name[i]<<"\t";
cout<<money[i]<<"\t元 * ";
cout<<inventory[i]<<endl;
}
}
if(checkout==0)
cout<<"\t(空白)"<<endl;
cout<<"-----------------------------------"<<endl;
cout<<"一共要付"<<checkout+300<<"元!(300塊運費)"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
張健勳
時間:
2016-4-29 22:28
備註 : 我的有問題但不知如何解決 請老師解答 謝謝
#include<iostream>
using namespace std;
int main ()
{
cout<<"☆★☆《影武的網路速食店》☆★☆"<<endl;
cout<<endl;
cout<<"〔商品價目表〕"<<endl;
string list[8]={"薯條","漢堡","可樂","雪碧","奶昔","紅茶","披薩","結帳"};
int money[7]={50,80,45,45,55,45,299};
for ( int i=0 ; i<8 ; i++)
{
cout<<"("<<i+1<<")"<<list[i]<<""<<"\t";
if (i!=7){
cout<<money[i]<<"元"<<endl;
}
}
cout<<endl;
int sum=0;
while (true)
{
int a=0,b=0;
cout<<"請輸入代碼"<<endl;
cin>>a;
if(a==8){
break;
}else{
cout<<"數量"<<endl;
cin>>b;
inventory[a-1]+=b;
sum += money[a-1]*b;
}
cout<<"《收據》"<<endl;
cout<<"影武網路速食店"<<endl;
cout<<"地址 : 火星芭樂國香蕉市西瓜區哈密瓜社區一路0號"<<endl;
cout<<"電話 : 您播的電話是空號,請查明後再播,謝謝!"<<endl;
cout<<"購買日期 : 3684年13月32日 "<<endl;
cout<<"購買時間 : 25時83分92秒"<<endl;
cout<<"服務人員 : 魔法師影武"<<endl;
cout<<"*請於25分鐘後至本店取餐*"<<endl;
cout<<"-----------------------------------"<<endl;
for(int i=0;i<=6;i++)
{
if(inventory[i]!=0)
{
cout<<list[i]<<"\t";
cout<<money[i]<<"\t元*";
cout<<inventory[i]<<endl;
}
}
if(sum==0)
cout<<"\t(空白)"<<endl;
cout<<"-----------------------------------"<<endl;
}
cout<<"總金額"<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
張健勳
時間:
2016-4-30 10:46
完成修正版
#include<iostream>
using namespace std;
int main ()
{
cout<<"☆★☆《影武的網路速食店》☆★☆"<<endl;
cout<<endl;
cout<<"〔商品價目表〕"<<endl;
string list[8]={"薯條","漢堡","可樂","雪碧","奶昔","紅茶","披薩","結帳"};
int inventory[7]={0,0,0,0,0,0,0};
int money[7]={50,80,45,45,55,45,299};
for ( int i=0 ; i<8 ; i++)
{
cout<<"("<<i+1<<")"<<list[i]<<""<<"\t";
if (i!=7){
cout<<money[i]<<"元"<<endl;
}
}
cout<<endl;
int sum=0;
while (true)
{
int a=0,b=0;
cout<<"請輸入代碼"<<endl;
cin>>a;
if(a==8){
break;
}else{
cout<<"數量"<<endl;
cin>>b;
inventory[a-1]+=b;
sum += money[a-1]*b;
}
}
cout<<"《收據》"<<endl;
cout<<"影武網路速食店"<<endl;
cout<<"地址 : 火星芭樂國香蕉市西瓜區哈密瓜社區一路0號"<<endl;
cout<<"電話 : 您播的電話是空號,請查明後再播,謝謝!"<<endl;
cout<<"購買日期 : 3684年13月32日 "<<endl;
cout<<"購買時間 : 25時83分92秒"<<endl;
cout<<"服務人員 : 魔法師影武"<<endl;
cout<<"*請於25分鐘後至本店取餐*"<<endl;
cout<<"-----------------------------------"<<endl;
for(int i=0;i<7;i++)
{
if(inventory[i]!=0)
{
cout<<list[i]<<"\t";
cout<<money[i]<<"*";
cout<<inventory[i]<<endl;
}
}
if(sum==0)
cout<<"\t(空白)"<<endl;
cout<<"-----------------------------------"<<endl;
cout<<"總金額"<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
蔡庭豪
時間:
2016-4-30 11:06
本帖最後由 蔡庭豪 於 2016-4-30 11:24 編輯
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int number[7]={450,550,325,200,660,150,380};
int count[7]={0,0,0,0,0,0,0};
string name[8]={"遙控汽車 ","飛機模型 ","足球 ","拼圖 ","玩具gun","可愛玩偶 ","籃球 ","結帳"};
cout<<"======================================"<<endl;
cout<<"===智障玩具店========================="<<endl;
cout<<"......................................"<<endl;
cout<<"===商品價目表========================="<<endl;
for(int i=0;i<7;i++)
{
cout<<"("<<i+1<<")"<<name[i]<<"\t";
if(i!=7)
{
cout<<number[i]<<"元"<<endl;
}
}
int sum = 0;
while(true)
{
int x=0,y=0;
cout<<"請輸入代碼(按8結帳):";
cin>>x;
if(x==8)
{
break;
}
else
{ cout<<"請輸入數量:";
cin>>y;
count[x-1]+=y;
sum+=number[x-1]*y;
}
}
cout<<"[購物清單]"<<endl;
cout<<"---------------------------------"<<endl;
for(int i=0;i<7;i++)
{
if(count[i]!=0)
{
cout<<name[i]<<" "<<number[i]<<"*"<<count[i]<<"="<<number[i]*count[i]<<endl;
}
}
cout<<"---------------------------------"<<endl;
cout<<"總共"<<sum<<"元"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
吳承勳
時間:
2016-4-30 11:18
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int count[7]={0,0,0,0,0,0,0};
int price[7]={790, 870, 110, 230, 950, 770, 375};
string name[8]={"遙控汽車","飛機模型","足球","拼圖","玩具槍","可愛玩偶","籃球","結帳"};
cout << "[商品價目表]" << endl;
for(int i = 0; i < 7; i++)
cout << "(" << i+1 << ")" << name[i] << " " << "\t" << price[i] << "元" << endl;
cout << "(8)" << name[7] <<endl;
int sum=0;
int a=0;
cout << "===============================" << endl;
while(a!=8){
int c;
cout << "請輸入商品代碼:";
cin >> a;
if (a==8){
break;
} else {
cout << "數量:";
cin >> c;
sum+=price[a-1]*c;
count[a-1]+=c;
}
}
cout << "===============================" << endl;
cout << "購物清單:" << endl;
for(int i = 0; i < 7; i++)
{
if(count[i] > 0)
{
cout << name[i] << " " << price[i] << " " << count[i] << endl;
}
}
cout << sum << endl;
cout << "===============================" << endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2