




版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進(jìn)行舉報或認(rèn)領(lǐng)
文檔簡介
1、程序代碼N:最終改進(jìn)版代碼(利用結(jié)構(gòu)體儲存多種類型的數(shù)據(jù))好處:比數(shù)組能儲存更多類型的數(shù)據(jù)!#includeiostream>include<string>includecstdlib> /常用函數(shù)庫 using namespace std;/在c+中struct和類的區(qū)別在于struct不能有方法,所有成員是public的/struct Roomint Number;int Price;int State;int days;string Name;string Phone;string ID;;/room; 可以在聲明struct的時候聲明一個struct實例Room
2、 room80;class BookRoom /定義預(yù)定房間類 private:string cName; /顧客姓名int stayTime; /預(yù)定天數(shù)int roomType; /房間類型(1.標(biāo)準(zhǔn)單人間 2.大床房 3.標(biāo)準(zhǔn)雙人間 4. 套房)string phoneNum; / 預(yù)留手機(jī)號public: void setData() string name; int time; int type; string num; cout”您好,請輸入您的姓名:”<endl;cin>name; cName=name;cout<<”預(yù)定天數(shù)為:”<endl; ci
3、n>>time; stayTime=time;cout<"想要預(yù)定的房間類型:1。標(biāo)準(zhǔn)單人間 100/天 2.大床房 200/天 3.標(biāo)準(zhǔn)雙人間 300/天 4.套房400/天"<endl;cin>type; roomType=type;cout"預(yù)留手機(jī)號:"endl;cin>>num; phoneNum=num;void Book()cout<"正在預(yù)定.。”endl;switch(this>roomType)case 1:for(int i=0;i20;i+)if (roomi。Sta
4、te=0) /房間無人占用且無人預(yù)定 roomi.days=thisstayTime;roomi.Name=this>cName;roomi。Phone=this->phoneNum;roomi.Price*=this->stayTime;cout<<"預(yù)定成功!房間號:"<<roomi.Numberendl<endl;roomi。State=1;break; /已被預(yù)訂 else cout<roomi。Number<<”號房間已有人”<endl;break;case 2:for(int i=20;i&
5、lt;40;i+) if(roomi。State=0) roomi。days=thisstayTime; roomi。Name=this-cName;roomi。Phone=this->phoneNum;roomi.Price*=this->stayTime; cout<"預(yù)定成功!房間號:”roomi.Numberendl<endl;roomi。State=1; break; else cout<roomi。Number<<”號房間已有人”<endl;break;case 3:for(int i=40;i60;i+)if(roomi.
6、State=0) roomi.days=this->stayTime; roomi.Name=this->cName;roomi.Phone=this->phoneNum;roomi。Price*=this-stayTime; cout”預(yù)定成功!房間號:"<<roomi。Number<endl<<endl;roomi.State=1; break; else cout<<roomi。Number<”號房間已有人"<<endl;break;case 4:for(int i=60;i<80;i
7、+)if(roomi.State=0) roomi。days=thisstayTime; roomi。Name=this->cName;roomi。Phone=this->phoneNum;roomi.Price=this-stayTime; cout<"預(yù)定成功!房間號:”<<roomi。Numberendl<endl;roomi。State=1; break;else cout<<roomi.Number<”號房間已有人"<endl;break;default:cout<”您輸入的房間類型有誤!”<
8、endl; ;class CheckIn /定義辦理入住類private:string cName;string cSex;string idNum; /身份證號 int check_inDate; /入住日期 int stayTime; int roomType; string phoneNum;public:void unbooked()string name;string sex;string idnum;int date;int time;int type;string num;cout"客戶姓名:"<endl; cin>name; cName=name
9、;cout"客戶性別:”<endl; cin>sex; cSex=sex; cout<<”客戶身份證號:"<endl; cin>>idnum; idNum=idnum;cout<”入住日期:”<<endl; cindate; check_inDate=date;cout<"占用天數(shù):"endl; cin>>time;stayTime=time;cout<"房間類型:1.標(biāo)準(zhǔn)單人間 100/天 2。大床房 200/天 3。標(biāo)準(zhǔn)雙人間 300/天 4.套房 400/
10、天"<endl; cin>type;roomType=type;cout<”客戶手機(jī)號:”endl; cinnum; phoneNum=num;switch(this-roomType)case 1:for(int i=0;i20;i+)if(roomi.State=0)roomi。days=this-stayTime;roomi.Name=this-cName;roomi.Phone=thisphoneNum;roomi。Price*=thisstayTime;roomi。ID=this>idNum;cout<<”入住成功!房間號:”<ro
11、omi.Number<endlendl;cout<<”請支付200元押金”<<endl<<endl;roomi.State=1;break; else cout<”抱歉,該房間類型沒有了"<<endl;break;case 2:for(int i=20;i40;i+)if(roomi。State=0)roomi.days=this>stayTime;roomi。Name=this->cName;roomi。Phone=this>phoneNum;roomi。Price*=this-stayTime;room
12、i。ID=thisidNum;cout<"入住成功!房間號:”<roomi。Number<endlendl;cout<”請支付400元押金”<endl<<endl;roomi。State=1;break; else cout<”抱歉,該房間類型沒有了”<endl;break;case 3:for(int i=40;i60;i+)if(roomi.State=0)roomi。days=this->stayTime;roomi。Name=this-cName;roomi.Phone=thisphoneNum;roomi.Pric
13、e*=this-stayTime;roomi.ID=this->idNum;cout<"入住成功!房間號:"roomi.Number<endlendl;cout<<”請支付600元押金”<endlendl;roomi.State=1;break; else cout<<"抱歉,該房間類型沒有了”<endl;break;case 4:for(int i=60;i80;i+)if(roomi.State=0)roomi。days=this-stayTime;roomi。Name=this-cName;roomi。P
14、hone=this>phoneNum;roomi。Price*=this->stayTime;roomi。ID=this-idNum;cout<"入住成功!房間號:”roomi.Number<endlendl;cout”請支付800元押金"<endl<<endl;roomi。State=1;break; else cout<"抱歉,該房間類型沒有了"<endl;break;default:cout<<"您輸入的房間類型有誤!”<<endl; void booked()
15、string compareItem;string id_num;cout<"請輸入您的姓名或者手機(jī)號:”endl;cin>compareItem;for(int i=0;i<80;i+)if(roomi.Name=compareItem|roomi。Phone=compareItem)cout<<"驗證成功!請支付:”<(roomi.Price2)<”元押金”<endl;cout<”請登記客戶的身份證號:"<endl;cin>id_num;idNum=id_num;roomi.ID=idNum;c
16、out<"房間號為:” roomi。Number<endl”歡迎入住!”<endl<endl;break; ;class checkOutprivate:string name;int number;int days;int price;public:void checkout()int expense;cout<"請輸入房間號:"endl; cin>number;cout<"請輸入姓名:"endl; cinname;cout<”請輸入實際住宿天數(shù):"<<endl; cind
17、ays; for(int i=0;i80;i+)if((roomi。Name=name) (roomi.Number=number))expense=days(roomi.Number/100*100);cout<"房間號為"roomi.Number"的房間實際消費為"<expense<"元"<endl;cout<”押金為:”<<roomi.Price<endl;if(expense>roomi.Price) cout”請補(bǔ)交”<<(expenseroomi。Price
18、)<<"元”<endl;else cout"退回:”(roomi。Priceexpense)<"元”<<endl; break;else cout<roomi。Number<"號房不符合"endl;cout<"房費核算清后請安任意鍵繼續(xù)”endl<endl; system("pause");cout<”感謝入住本酒店,歡迎下次光臨!"endlendl;;void menu()cout"歡迎使用酒店管理系統(tǒng)!"endl;c
19、out<”請選擇:"<endl;cout<<”1。預(yù)定房間”<endl;cout”2.辦理入住"endl;cout<”3。退房結(jié)賬”<endl;cout<”4.退出系統(tǒng)"<endl; void init()int n=101;for(int i=0;i<20;i+)roomi.Number=n+;roomi。Price=100;roomi。State=0;n=201; for(int i=20;i40;i+)roomi.Number=n+;roomi。Price=200;roomi。State=0;n=3
20、01;for(int i=40;i<60;i+)roomi。Number=n+;roomi。Price=300;roomi.State=0;n=401;for(int i=60;i80;i+)roomi.Number=n+;roomi.Price=400;roomi.State=0;int main(void) init(); int flag=1; while(flag)menu();int c;cin>>c; switch(c) case 1: BookRooma=new BookRoom; a>setData(); a-Book(); break; case 2:
21、 CheckInb=new CheckIn; cout”您有預(yù)定嗎? 1.已預(yù)定 2。未預(yù)定”<<endl; int c; cin>c; switch(c) case 1: b>booked(); break;case 2:b-unbooked();break;default:cout<”輸入有誤!"<endl; break;case 3: checkOut c=new checkOut; c>checkout(); break;case 4: cout<<”謝謝使用,再見!”<endl; flag=0; break; de
22、fault:cout<”輸入有誤!"<<endl; return 0;O:最初廢除版(利用數(shù)組)因為數(shù)組只能簡單的儲存一種類型的數(shù)據(jù),例如字符和數(shù)字.而酒店管理系統(tǒng)這種情境,一個房間要儲存多種數(shù)據(jù),例如客戶姓名、客戶性別、預(yù)訂房間號、客戶預(yù)留手機(jī)號、客戶占用天數(shù)、客戶身份證號以及押金和實際花銷等。因此我選用了結(jié)構(gòu)體來儲存.以下是Old version:#include<iostream>include<string>using namespace std;int room_num420; /定義數(shù)組,共4個樓層,每個樓層20個房間,一層一類型
23、class BookRoom /定義預(yù)定房間類 private:string cName; /顧客姓名int stayTime; /預(yù)定天數(shù)int roomType; /房間類型(1。標(biāo)準(zhǔn)單人間 2。大床房 3.標(biāo)準(zhǔn)雙人間 4。 套房)string phoneNum; / 預(yù)留手機(jī)號(也可使用longint) public: void setData() string name; int time; int type; string num; cout<”您好,請輸入您的姓名:"<endl; cinname; cName=name;cout<<"預(yù)定
24、天數(shù)為:"<endl; cin>time; stayTime=time;cout<”想要預(yù)定的房間類型:1。標(biāo)準(zhǔn)單人間 2.大床房 3。標(biāo)準(zhǔn)雙人間 4. 套房”endl; cin>type; roomType=type;cout<<”預(yù)留手機(jī)號:"endl; cinnum; phoneNum=num;void Book()cout<”正在預(yù)定。"<endl;switch(this>roomType)case 1:for(int i=0;i<20;i+)if (room_num1i=0) /房間無人占用且無
25、人預(yù)定 cout<"預(yù)定成功!房間號:10"<i+1<endl;room_num1i=1;break; /已被預(yù)訂 else cout<”該類型房間沒有了”endl; break;case 2:for(int i=0;i20;i+) if(room_num2i=0) cout<<"預(yù)定成功!房間號:20”<i+1<endl;room_num2i=1; break;else cout<"該類型房間沒有了"<endl; break;case 3:for(int i=0;i<20;i+
26、)if(room_num3i=0) cout<”預(yù)定成功!房間號:30”i+1<endl;room_num3i=1; break;else cout<<"該類型房間沒有了"<endl; break;case 4:for(int i=0;i<20;i+)if(room_num4i=0) cout”預(yù)定成功!房間號:40”<i+1<endl;room_num4i=1; break;else cout”該類型房間沒有了”endl; break;default:cout<"您輸入的房間類型有誤!"<&l
27、t;endl; ;;class Checkin /定義辦理入住類private:string cName;string cSex;string cId; /身份證號 string phoneNum;int check_inDate; /入住時間 int stayTime;int Room_num;public:void setData()string name;string sex;string id;string num;int date;int time;int room_num;cout<"客戶姓名:”endl;cin>name;cName=name;cout<
28、;"性別:"<endl;cinsex;cSex=sex;cout<<"身份證號:"endl;cin>>id;cId=id;cout<"手機(jī)號:"<endl;cin>>num;phoneNum=num;cout<”登記入住時間:"<<endl;cin>>date;check_inDate=date;cout<”入住天數(shù):"<<endl;cintime;stayTime=time;cout<"房間號:"endl;cin&
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025年財務(wù)成本管理試題分析及答案
- 調(diào)試與測試技巧2025年計算機(jī)二級Python試題及答案
- 家長與考生的Python考試指南及試題答案
- 文學(xué)作品的數(shù)據(jù)分析與評價試題及答案
- 計算機(jī)二級C++考試策略與試題及答案
- 邏輯框架在財務(wù)管理中的應(yīng)用試題及答案
- 角色沖突與情節(jié)發(fā)展的關(guān)系試題及答案
- 法學(xué)與社會科學(xué)的結(jié)合試題及答案
- 代碼重構(gòu)技巧計算機(jī)二級C++試題及答案
- 適合新手的2025年Web考試試題及答案
- 材料科學(xué)基礎(chǔ)基礎(chǔ)知識點總結(jié)
- 數(shù)控銑工圖紙(60份)(共60頁)
- 新時達(dá)-奧莎(sigriner)iAStar-S32電梯專用變頻器使用說明書
- 《青年友誼圓舞曲》教案
- 馬清河灌區(qū)灌溉系統(tǒng)的規(guī)劃設(shè)計課程設(shè)計
- 惠州市出租車駕駛員從業(yè)資格區(qū)域科目考試題庫(含答案)
- 加工設(shè)備工時單價表
- 高脂血癥藥物治療ppt課件
- 單開、菱形及復(fù)式交分道岔的檢查方法帶圖解
- 瀝青拌和站管理制度匯編(正式版)
- 高層建筑等電位聯(lián)結(jié)安裝技術(shù)分析探討
評論
0/150
提交評論