C++實現(xiàn)賓館房間管理系統(tǒng)
本文實例為大家分享了C++實現(xiàn)賓館房間管理系統(tǒng)的具體代碼,供大家參考,具體內(nèi)容如下
一、問題描述
設計一個程序?qū)崿F(xiàn)對賓館房間的基本管理,可以實現(xiàn):客房信息的錄入功能;客人入住登記、客人退房結(jié)算;客房信息瀏覽功能,瀏覽全部客戶的信息,客房信息和客戶信息分別保存于不同文件;客房信息查詢,查詢空房間情況,實現(xiàn)按房間號查詢等。
二、基本要求
(1)使用面向?qū)ο缶幊趟枷刖帉戦_發(fā)過程中需要用到的類,比如:至少包含四個類:日期類,客房類,主要包含客房信息(房號類型,是否有客人等)及相關操作;客人類,主要完 成客戶信息(身份證,入住時間,姓名,性別等)的相關操作;管理類實現(xiàn)對客房的管理。
(2)輸入和輸出可以使用文本文件重定向輸入(保存數(shù)據(jù)為磁盤文件);也可以使用標準輸入輸出進行(提交時需要提交TXT格式輸入數(shù)據(jù))。比如:room.txt 的文件,文件中應包含 20 條以上記錄(房間的初始狀態(tài)),guest.txt 的文本文件,包含 10 條以上客人記錄。 在運行程序時自動載入。
(3)基本功能要求具有增、刪、改、查。
基本流程圖
#include<iostream> #include<fstream> #include<string> #include<iomanip> #include<windows.h>? #include<conio.h> #define Max 100? using namespace std; class Data//日期類,記錄交易時間? { ?? ?public: ?? ??? ?Data(){}//缺省構(gòu)造函數(shù) ?? ??? ?~Data(){}//析構(gòu)函數(shù) ?? ??? ?void SetDate(int year,int month,int day)//接收輸入的日期? ?? ??? ?{ ?? ??? ??? ?this->year=year; ?? ??? ??? ?this->month=month; ?? ??? ??? ?this->day=day; ?? ? ?? ?}? ?? ? ?? ?int getyear(){ ?? ? ?? ??? ?return year; ?? ??? ? } ?? ??? ?int getmonth(){ ?? ? ?? ??? ?return month; ?? ??? ? } ?? ??? ?int getday(){ ?? ? ?? ??? ?return day; ?? ??? ? } ?? ?private: ?? ??? ?int year;? ?? ??? ?int month; ?? ??? ?int day;? };? class Room { ?? ?public: ?? ??? ?Room *r[Max];//房間對象指針數(shù)組?? ??? ??? ??? ??? ??? ??? ??? ??? ? ?? ??? ?int Room_count;?? ?//記錄房間數(shù)量?? ? ?? ??? ?Room(int Number,string Type,double Price,string Whether)//構(gòu)造函數(shù)? ?? ??? ?{ ?? ??? ??? ?this->Number=Number; ?? ??? ??? ?this->Type=Type; ?? ??? ??? ?this->Whether=Whether; ?? ??? ??? ?this->Price=Price; ?? ??? ??? ??? ??? ?} ?? ??? ?int InputNumber()?? ?{return Number;} ?? ??? ?string InputType(){return Type;} ?? ??? ?string InputWhether(){return Whether;} ?? ??? ?double InputPrice(){return Price;} ?? ??? ?void SetWether(string _state)?? ?{Whether=_state;}? ?? ??? ?void show()?? ?{cout<<"房號: ?"<<Number<<"\t"<<"房間類型: ?"<<Type<<"\t"<<"房間狀態(tài): ?"<<Whether<<"\t"<<"價格: ? "<<Price<<endl;}?? ? ?? ?protected: ?? ??? ?int Number; //房號? ?? ??? ?string Type;//類型? ?? ??? ?string Whether;//是否有客人? ?? ??? ?double Price;//價格? ?? ??? ??? ? }; class Guest { ?? ?public: ?? ??? ?Guest *g[Max];?? ?//客人對象指針數(shù)組?? ??? ??? ??? ??? ??? ??? ??? ? ?? ??? ?int Guest_count;?? ?//記錄客人數(shù)量?? ? ?? ??? ?Guest(int number,string Name,int Id,string sex,string Intime,int days) //構(gòu)造函數(shù)? ?? ??? ?{ ?? ??? ??? ?this->Name=Name;?? ?this->Id=Id;?? ?this->sex=sex; this->number=number; ?? ??? ??? ?this->Intime=Intime;?? ?this->days=days; ?? ??? ?} ?? ??? ?int InputNumber(){return number;} ?? ??? ?string InputName(){return Name;} ?? ??? ?string InputSex(){return sex;} ?? ??? ?int InputDays(){return days;} ?? ??? ?string InputIntime(){return Intime;} ?? ??? ?int InputId(){return Id;} ?? ??? ?void show()? ?? ??? ?{ ?? ??? ??? ?cout<<"顧客姓名: ?"<<Name<<"\t 身份證號: ?"<<Id<<"\t性別: ?"<<sex<<"\t入住時間: ?"<<Intime<<"\t入住天數(shù): ?"<<days<<endl; ?? ??? ?} ?? ?protected: ?? ??? ?int number;//房號? ?? ??? ?string Name;//顧客姓名? ?? ??? ?int Id;//身份證號? ?? ??? ?string sex;//性別? ?? ??? ?string Intime;//入住時間? ?? ??? ?int days; //入住天數(shù) }; class Manage? { ?? ?public:?? ? ?? ??? ?Guest *g[Max];?? ?//客人對象指針數(shù)組?? ??? ??? ??? ??? ??? ??? ??? ? ?? ??? ?int Guest_count;?? ?//記錄客人數(shù)量?? ??? ? ?? ??? ?Room *r[Max];//房間對象指針數(shù)組?? ??? ??? ??? ??? ??? ??? ??? ??? ? ?? ??? ?int Room_count;?? ?//記錄房間數(shù)量 ?? ?/*操作函數(shù)*/ ?? ??? ?void IncreaseRoom();//添加客房信息? ?? ??? ?void Check_In();?? ?//刪除客房信息,辦理入住 ?? ??? ?void Check_Out();?? ?//退房?? ? ?? ??? ?int Payment();//結(jié)賬? ?? ??? ?void Display(int n);//瀏覽所有信息(1瀏覽房間,2瀏覽顧客) ?? ??? ??? ??? ? ?? ??? ?void ReadData(); ?//從文件中獲取房間和顧客的信息 ?? ??? ?void WriteData(int n);//向文件中寫入所有的信息 ?? ??? ?void WriteRoom(Room *r);//客房信息寫入? ?? ??? ?void WriteGuest(Guest *g);//顧客信息寫入? ?? ?/*查詢菜單 */? ?? ??? ?void SearchMenu();//查詢主菜單? ?? ??? ?void SearchType();//查詢所有空房間;? ?? ??? ?void SearchNumber();//按房間號查詢?? ??? ? };? static int i=0;? void Manage::SearchMenu() { ?? ?int n; ?? ?system("cls"); ?? ?cout<<"===================================="<<endl; ?? ?cout<<"= ? ? ? ? 查 ? 詢 ? 菜 ? 單 ? ? ? ?="<<endl; ?? ?cout<<"===================================="<<endl; ?? ?cout<<"========= ?1、查 詢 空 房 ? ?======="<<endl; ?? ?cout<<"========= ?2、按房間號查詢 ? ======="<<endl; ?? ?cout<<"===================================="<<endl; ?? ?cout<<endl<<"請選擇: "; ?? ?cin>>n; ?? ?switch(n) ?? ?{ ?? ??? ?case 1:SearchType(); break;? ?? ??? ?case 2:SearchNumber();break; ?? ?} ?}? void Manage::IncreaseRoom()//添加房間? { ?? ?string type,Whether; ?? ?double price; ?? ?int number; ?? ?cout<<"請輸入房號: ";?? ?cin>>number; ?? ?cout<<"請輸入房間類型: ";?? ?cin>>type; ?? ?cout<<"請輸入價格: ";?? ?cin>>price; ?? ?cout<<"請輸入房間狀態(tài): ";?? ?cin>>Whether; ?? ?WriteRoom(new Room(number,type,price,Whether)); } void Manage::Check_In()//刪除房間信息,即入房登記 { ?? ?ReadData(); ?? ?SearchType(); ?? ?string name,intime,sex,type; ?? ?int days,number; ?? ?int id; ?? ?cout<<"請輸入房號: ";?? ?cin>>number; ?? ?cout<<"請輸入顧客的姓名: "; cin>>name; ?? ?cout<<"請輸入顧客的身份證號: ";?? ?cin>>id; ?? ?cout<<"請輸入顧客的性別: "; cin>>sex; ?? ?cout<<"請輸入入住日期: ";?? ?cin>>intime; ?? ?cout<<"請輸入入住天數(shù): "; cin>>days; ?? ?for(i=0;i<Room_count;i++) ?? ?{ ?? ??? ?if(number==r[i]->InputNumber()) ?? ??? ?{ ?? ??? ??? ?WriteGuest(new Guest(number,name,id,sex,intime,days)); ?? ??? ??? ?r[i]->SetWether("有"); ?? ??? ??? ?WriteData(1); ?? ??? ??? ?cout<<"住房登記成功!"<<endl;? ?? ??? ?} ?? ? }? }? int Manage::Payment()//退房結(jié)賬? { ?? ?ReadData(); ?? ?Display(2); ?? ?int number; ?? ?cout<<"請輸入房號: ";?? ??? ?cin>>number; ?? ?for(i=0;i<Guest_count;i++) ?? ?{ ?? ??? ?if(number==g[i]->InputNumber()) ?? ??? ?{ ?? ??? ??? ?return i; ?? ??? ?} ?? ? }? }? void Manage::Check_Out() { ?? ?int x=Payment(); ?? ?ReadData(); ?? ?for(i=0;i<Room_count;i++) ?? ?{ ?? ??? ?if(g[x]->InputNumber()==r[i]->InputNumber()) ?? ??? ?{ ?? ??? ??? ?r[i]->SetWether("無"); ?? ??? ??? ?cout<<"退房成功,您一共消費了 "<<g[x]->InputDays() *r[i]->InputPrice()<<" 元"<<endl;? ?? ??? ??? ?WriteData(1); ?? ??? ?}?? ? ?? ? }? ?? ?g[x]=NULL; ?? ?WriteData(2); } void Manage::Display(int n)//瀏覽所有房間信息? { ?? ?ReadData(); ?? ?switch(n){ ?? ?case 1: ?? ??? ?for(i=0; i<Room_count-1; i++) ?? ??? ?{ ?? ??? ??? ?cout<<"房號:"<<r[i]->InputNumber()<<"\t房間類型: "<<r[i]->InputType()<<"\t房間價格: "<<r[i]->InputPrice()<<"\t房間狀態(tài): "<<r[i]->InputWhether()<<endl<<endl;? ?? ??? ?} break; ?? ?case 2: ?? ??? ?for(i=0;i<Guest_count-1;i++) ?? ??? ?{ ?? ??? ??? ?cout<<"房間號: "<<g[i]->InputNumber()<<"\t顧客姓名: "<<g[i]->InputName()<<"\t身份證號: "<<g[i]->InputId()<<"\t顧客性別:"<<g[i]->InputSex()<<"\t入住時間: "<<g[i]->InputIntime()<<"\t入住天數(shù): "<<g[i]->InputDays()<<endl<<endl;? ?? ??? ?} break; ?? ?} } void Manage::ReadData() { ?? ?fstream Rin,Gin; ?? ?Rin.open("room.txt",ios::in);//打開文件? ?? ?if(!Rin) ?? ?{ ?? ??? ?cout<<"未找到room文件,請先建立文件!"<<endl; ?? ??? ?return; ?? ?} ?? ?Room_count=0; ?? ?while(!Rin.eof()){ ?? ??? ?string type,Whether; ?? ??? ?double price; ?? ??? ?int number; ?? ??? ?Rin>>number>>type>>price>>Whether; ?? ??? ?r[Room_count++]=new Room(number,type,price,Whether); ?? ?} ?? ?Rin.close();//關閉文件? ?? ?Gin.open("guest.txt",ios::in); ?? ?if(!Gin) ?? ?{ ?? ??? ?cout<<"未找到guest文件,請先建立文件!"<<endl; ?? ??? ?return;?? ? ?? ?} ?? ?Guest_count=0; ?? ?while(!Gin.eof()){ ?? ??? ?string name,intime,sex; ?? ??? ?int days,number; ?? ??? ?int id; ?? ??? ?Gin>>number>>name>>id>>sex>>intime>>days; ?? ??? ?g[Guest_count++]=new Guest(number,name,id,sex,intime,days); ?? ?} ?? ?Gin.close(); } void Manage::WriteData(int n) { ?? ?switch(n) ?? ?{ ?? ??? ?case 1: ?? ??? ?{ ?? ??? ?ofstream Rout("room.txt",ios::trunc); //用二進制的方法打開顧客文件 ,覆蓋掉之前的所有信息重新寫入? ?? ??? ?for(i=0; i<Room_count-1; i++) //根據(jù)顧客數(shù)量判斷輸入幾組信息? ?? ??? ?{ ?? ??? ??? ?if(r[i]!=NULL) ?? ??? ??? ?{ ?? ??? ??? ??? ?WriteRoom(r[i]);//調(diào)用構(gòu)造函數(shù)來創(chuàng)建顧客信息? ?? ??? ??? ?} ?? ??? ?} ?? ??? ?Rout.close(); break;} ?? ??? ?case 2:{ ?? ??? ?ofstream Gout("guest.txt",ios::trunc); //用二進制的方法打開顧客文件 ,覆蓋掉之前的所有信息重新寫入? ?? ??? ?for(i=0; i<Guest_count-1; i++) //根據(jù)顧客數(shù)量判斷輸入幾組信息? ?? ??? ?{ ?? ??? ??? ?if(g[i]!=NULL) ?? ??? ??? ?{?? ? ?? ??? ??? ??? ?WriteGuest(g[i]);//調(diào)用構(gòu)造函數(shù)來創(chuàng)建顧客信息? ?? ??? ??? ?} ?? ??? ?} ?? ??? ?Gout.close();break;} ?? ?} }? void Manage::WriteRoom(Room *r)//儲存單個信息? { ?? ?ofstream Rout("room.txt",ios::app);//打開房間文件,追加讀寫,不會覆蓋掉之前的所有信息? ?? ?Rout<<r->InputNumber()<<"\t"<<r->InputType()<<"\t"<<r->InputPrice()<<"\t"<<r->InputWhether()<<endl; ?? ?Rout.close(); } void Manage::WriteGuest(Guest *g)//儲存單個信息? { ?? ?ofstream Gout("guest.txt",ios::app);//打開顧客文件,追加讀寫,不會覆蓋掉之前的所有信息? ?? ?Gout<<g->InputNumber()<<"\t"<<g->InputName()<<"\t"<<g->InputId()<<"\t"<<g->InputSex()<<"\t"<<g->InputIntime()<<"\t"<<g->InputDays()<<endl; ?? ?Gout.close(); } void Manage::SearchType() { ?? ?ReadData(); ?? ?for(i=0;i<Room_count;i++) ?? ?{ ?? ??? ?if(r[i]->InputWhether()=="無") ?? ??? ??? ?{? ?? ??? ??? ?r[i]->show();} ?? ??? ?}?? ? } void Manage::SearchNumber() { ?? ?ReadData(); ?? ?int number,n; ?? ?cout<<"請輸出要查詢的房間號: "; cin>>number; ?? ?for(i=0;i<Room_count-1;i++) ?? ?{ ?? ??? ?if(number==r[i]->InputNumber()) ?? ??? ??? ?r[i]->show(); ?? ??? ?} ?? ?for(i=0;i<Guest_count-1;i++) ?? ?{ ?? ??? ?if(g[i]->InputNumber()==number) ?? ??? ??? ?g[i]->show(); ?? ??? ?}?? ? } int main() { ?? ?Manage M; ?? ?int n; ?? ?while(1) ?? ?{ ?? ??? ?system("cls");?? ? ?? ??? ?cout<<endl<<endl<<endl<<"\t\t\t賓 館 房 間 管 理 系 統(tǒng) ? ? "<<endl<<endl; ?? ??? ?cout<<"\t\t\t1、房 間 信 息 的 錄 入"<<endl<<endl; ?? ??? ?cout<<"\t\t\t2、顧 客 入 住 房 間 登 記"<<endl<<endl; ?? ??? ?cout<<"\t\t\t3、顧 客 退 房 結(jié) 賬"<<endl<<endl; ?? ??? ?cout<<"\t\t\t4、所 有 房 間 信 息 顯 示"<<endl<<endl; ?? ??? ?cout<<"\t\t\t5、所 有 顧 客 的 顯 示"<<endl<<endl; ?? ??? ?cout<<"\t\t\t6、查 詢 所 有 空 房 間"<<endl<<endl; ?? ??? ?cout<<"\t\t\t7、查 詢 指 定 的 房 間 號"<<endl<<endl; ?? ??? ?cout<<"\t\t\t8、退 出 系 統(tǒng)"<<endl<<endl; ?? ??? ?cout<<endl<<"請選擇: ?"; ?? ??? ?cin>>n;? ?? ??? ?cout<<endl<<endl; ?? ??? ?switch(n) ?? ??? ?{ ?? ??? ??? ?case 1:M.IncreaseRoom();getch();break; ?? ??? ??? ?case 2:M.Check_In();getch();break; ?? ??? ??? ?case 3:M.Check_Out();getch();break; ?? ??? ??? ?case 4:M.Display(1);getch();break; ?? ??? ??? ?case 5:M.Display(2);getch();break; ?? ??? ??? ?case 6: M.SearchType();getch();break; ?? ??? ??? ?case 7: M.SearchNumber();getch();break;?? ? ?? ??? ??? ?case 8:exit(0);?? ? ?? ??? ?}?? ??? ?? ?? ?} ?? ?return 0; ?}?
以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
Cocos2d-x 3.x入門教程(二):Node節(jié)點類
這篇文章主要介紹了Cocos2d-x 3.x入門教程(二):Node節(jié)點類,本文對Node節(jié)點類做了一個簡明講解及Node類提供的函數(shù)做了說明,需要的朋友可以參考下2014-11-11matlab模擬退火算法單約束車間流水線調(diào)度解決實現(xiàn)及示例
這篇文章主要為大家介紹了matlab模擬退火算法求解單約束車間流水線調(diào)度的實現(xiàn)及示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步2022-02-02NDK 數(shù)據(jù)結(jié)構(gòu)之隊列與棧等的實現(xiàn)
這篇文章主要介紹了NDK 數(shù)據(jù)結(jié)構(gòu)之隊列與棧等的實現(xiàn)的相關資料,希望通過本文大家能理解掌握這部分內(nèi)容,需要的朋友可以參考下2017-10-10