生活随笔
收集整理的這篇文章主要介紹了
宾馆房间管理系统(C++)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
賓館房間管理系統(tǒng)
一、問題描述
設(shè)計(jì)一個(gè)程序?qū)崿F(xiàn)對賓館房間的基本管理,可以實(shí)現(xiàn):客房信息的錄入功能;客人入住登記、客人退房結(jié)算;客房信息瀏覽功能,瀏覽全部客戶的信息,客房信息和客戶信息分別保存于不同文件;客房信息查詢,查詢空房間情況,實(shí)現(xiàn)按房間號(hào)查詢等。
二、基本要求
(1)使用面向?qū)ο缶幊趟枷刖帉戦_發(fā)過程中需要用到的類,比如:至少包含四個(gè)類:日
期類,客房類,主要包含客房信息(房號(hào)類型,是否有客人等)及相關(guān)操作;客人類,主要完 成客戶信息(身份證,入住時(shí)間,姓名,性別等)的相關(guān)操作;管理類實(shí)現(xiàn)對客房的管理。
(2)輸入和輸出可以使用文本文件重定向輸入(保存數(shù)據(jù)為磁盤文件);也可以使用標(biāo)
準(zhǔn)輸入輸出進(jìn)行(提交時(shí)需要提交TXT格式輸入數(shù)據(jù))。比如:room.txt 的文件,文件中應(yīng)包含 20 條以上記錄(房間的初始狀態(tài)),guest.txt 的文本文件,包含 10 條以上客人記錄。 在運(yùn)行程序時(shí)自動(dòng)載入。
(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
<<"房號(hào): "<<Number
<<"\t"<<"房間類型: "<<Type
<<"\t"<<"房間狀態(tài): "<<Whether
<<"\t"<<"價(jià)格: "<<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 身份證號(hào): "<<Id
<<"\t性別: "<<sex
<<"\t入住時(shí)間: "<<Intime
<<"\t入住天數(shù): "<<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
);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、按房間號(hào)查詢 ======="<<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
<<"請輸入房號(hào): "; cin
>>number
;cout
<<"請輸入房間類型: "; cin
>>type
;cout
<<"請輸入價(jià)格: "; 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
<<"請輸入房號(hào): "; cin
>>number
;cout
<<"請輸入顧客的姓名: "; cin
>>name
;cout
<<"請輸入顧客的身份證號(hào): "; 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()
{ReadData();Display(2);int number
;cout
<<"請輸入房號(hào): "; 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
<<"退房成功,您一共消費(fèi)了 "<<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
<<"房號(hào):"<<r
[i
]->InputNumber()<<"\t房間類型: "<<r
[i
]->InputType()<<"\t房間價(jià)格: "<<r
[i
]->InputPrice()<<"\t房間狀態(tài): "<<r
[i
]->InputWhether()<<endl
<<endl
; } break;case 2:for(i
=0;i
<Guest_count
-1;i
++){cout
<<"房間號(hào): "<<g
[i
]->InputNumber()<<"\t顧客姓名: "<<g
[i
]->InputName()<<"\t身份證號(hào): "<<g
[i
]->InputId()<<"\t顧客性別:"<<g
[i
]->InputSex()<<"\t入住時(shí)間: "<<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
++) {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
<<"請輸出要查詢的房間號(hào): "; 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、查 詢 指 定 的 房 間 號(hào)"<<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;}
總結(jié)
以上是生活随笔為你收集整理的宾馆房间管理系统(C++)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。