日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > c/c++ >内容正文

c/c++

宾馆房间管理系统(C++)

發布時間:2023/12/20 c/c++ 43 豆豆
生活随笔 收集整理的這篇文章主要介紹了 宾馆房间管理系统(C++) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

賓館房間管理系統

一、問題描述
設計一個程序實現對賓館房間的基本管理,可以實現:客房信息的錄入功能;客人入住登記、客人退房結算;客房信息瀏覽功能,瀏覽全部客戶的信息,客房信息和客戶信息分別保存于不同文件;客房信息查詢,查詢空房間情況,實現按房間號查詢等。
二、基本要求
(1)使用面向對象編程思想編寫開發過程中需要用到的類,比如:至少包含四個類:日
期類,客房類,主要包含客房信息(房號類型,是否有客人等)及相關操作;客人類,主要完 成客戶信息(身份證,入住時間,姓名,性別等)的相關操作;管理類實現對客房的管理。
(2)輸入和輸出可以使用文本文件重定向輸入(保存數據為磁盤文件);也可以使用標
準輸入輸出進行(提交時需要提交TXT格式輸入數據)。比如:room.txt 的文件,文件中應包含 20 條以上記錄(房間的初始狀態),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(){}//缺省構造函數~Data(){}//析構函數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];//房間對象指針數組 int Room_count; //記錄房間數量 Room(int Number,string Type,double Price,string Whether)//構造函數 {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"<<"房間狀態: "<<Whether<<"\t"<<"價格: "<<Price<<endl;} protected:int Number; //房號 string Type;//類型 string Whether;//是否有客人 double Price;//價格 }; class Guest {public:Guest *g[Max]; //客人對象指針數組 int Guest_count; //記錄客人數量 Guest(int number,string Name,int Id,string sex,string Intime,int days) //構造函數 {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入住天數: "<<days<<endl;}protected:int number;//房號 string Name;//顧客姓名 int Id;//身份證號 string sex;//性別 string Intime;//入住時間 int days; //入住天數 }; class Manage {public: Guest *g[Max]; //客人對象指針數組 int Guest_count; //記錄客人數量 Room *r[Max];//房間對象指針數組 int Room_count; //記錄房間數量/*操作函數*/void IncreaseRoom();//添加客房信息 void Check_In(); //刪除客房信息,辦理入住void Check_Out(); //退房 int Payment();//結賬 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<<"請輸入房間狀態: "; 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<<"請輸入入住天數: "; 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()//退房結賬 {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房間狀態: "<<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入住天數: "<<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++) //根據顧客數量判斷輸入幾組信息 {if(r[i]!=NULL){WriteRoom(r[i]);//調用構造函數來創建顧客信息 }}Rout.close(); break;}case 2:{ofstream Gout("guest.txt",ios::trunc); //用二進制的方法打開顧客文件 ,覆蓋掉之前的所有信息重新寫入 for(i=0; i<Guest_count-1; i++) //根據顧客數量判斷輸入幾組信息 {if(g[i]!=NULL){ WriteGuest(g[i]);//調用構造函數來創建顧客信息 }}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賓 館 房 間 管 理 系 統 "<<endl<<endl;cout<<"\t\t\t1、房 間 信 息 的 錄 入"<<endl<<endl;cout<<"\t\t\t2、顧 客 入 住 房 間 登 記"<<endl<<endl;cout<<"\t\t\t3、顧 客 退 房 結 賬"<<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、退 出 系 統"<<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;}

總結

以上是生活随笔為你收集整理的宾馆房间管理系统(C++)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。