亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

C++實現(xiàn)旅館住宿管理系統(tǒng)

 更新時間:2022年05月27日 16:23:39   作者:萬事勝意  
這篇文章主要為大家詳細介紹了C++實現(xiàn)旅館住宿管理系統(tǒng),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下

本文實例為大家分享了C++實現(xiàn)旅館住宿管理系統(tǒng)的具體代碼,供大家參考,具體內容如下

一、課程設計要實現(xiàn)的目的

1.預定房間:輸入顧客的姓名和身份證號碼,然后有單人間/天/100元、雙人間/天/200元、標準間/天/300元 三種房間類型可以選擇。最后=輸入預定天數(shù),從而系統(tǒng)計算出房費與預定的房間號。
2.入住功能:分該顧客已訂和未訂房間的兩種情況。對于已經預定的顧客,通過輸入姓名與身份證號碼從而入住預定的房間;對于沒有預定的顧客,執(zhí)行入住功能,過程與預定房間類似。
3.退房功能:輸入要退房的顧客姓名與身份證號碼來查找該顧客,然后輸入該顧客實際所住的天數(shù),計算出實際應付的房費與多支付或少支付的費用。
4.查詢功能:分為房間信息查詢與顧客了信息查詢兩種查詢方式。
   房間信息查詢可以顯示出空房間、已預定房間和已入住房間的房間號和房間數(shù)量。
   顧客信息查詢分為按姓名或按身份證號查找。兩種方式都是查詢出該顧客的預付費用和房間信息。
5.退出功能:退出系統(tǒng)。

二、總體設計

一個旅館管理系統(tǒng),必然涉及到房間對象,顧客對象等實體。這個系統(tǒng)初始化了60個房間,其中房間分三個等級,每個等級的價格不一樣,可以通過房間編號得到房間的等級。然后就是房間的分配問題,當有顧客要求預定或入住時,系統(tǒng)能夠根據(jù)用戶要求入住的等級到相應等級的房間中去查找一個還沒有預定的房間和一個沒有入住的空閑房間。
當啟動程序后,從Main函數(shù)開始運行,程序首先調用initial_room函數(shù)初始化60個房間的信息,包括房間編號,房間等級,房間價格,房間狀態(tài)。其中房間編號和房間等級有直接聯(lián)系,只要知道了房間編號就可以通過計算得到該房間的等級,房間狀態(tài)初始化時都等于0,表示該房間既沒有被預定,也沒有被入住,為空房間。然后調用welcome函數(shù),考慮到作為一個賓館管理系統(tǒng)的安全性,在本函數(shù)中要求只有通過輸入了正確的用戶名和密碼才能操作系統(tǒng)。此處賬號密碼都是123。當通過登陸認證后,就進入賓館管理系統(tǒng)了,在這里,系統(tǒng)給操作者顯示一個操作菜單:1.預定  2.入住  3.退房  4.查詢  5.退出,選擇不同的數(shù)字時就實現(xiàn)不同的功能。

三、詳細設計過程

1. 預定:作為一個旅館管理系統(tǒng),顧客可以提前進行房間的預定,操作者能根據(jù)用戶的需求查詢到適合顧客的房間。在這個系統(tǒng)中,這個功能是在Book_Room函數(shù)中實現(xiàn)的。首先,構造一個顧客對象,輸入顧客的信息,然后設置該顧客預定客房的天數(shù),設置顧客預定客房類型,根據(jù)用戶需要的客放標準到相應的類型客房去查找一個一個既沒有被預定也沒有入住的房間,然后把該房間對象結構體的狀態(tài)修改為已預定狀態(tài),同時將顧客對象的預定房間號屬性和住房費用計算出來并顯示到界面上,最后將住房顧客數(shù)加1。

2. 入?。哼@個功能是在go_in函數(shù)中實現(xiàn)的,程序首先判斷顧客是否訂房了,如果預定了房間,則要求輸入顧客姓名和身份證號碼,然后在所有的顧客中去查找此姓名和身份證號碼的顧客,如果匹配了就取得其房間號,然后根據(jù)房間號計算出該房間的類型,再根據(jù)該顧客要求預定住房的天數(shù)和該房間類型的價格計算出該顧客要繳納的費用,同時顯示到界面上,這時操作者對顧客進行收費,同時將該住房的狀態(tài)修改為已入住狀態(tài)(State=2);如果顧客沒有先預定房間,在這里可以實現(xiàn)先查找空房再入住的功能,同預定房間功能一樣,先建立一個顧客對象,然后設置入住天數(shù),選擇住房類型,根據(jù)房間類型查詢到一個空房,同時修改該房間的狀態(tài)為已入住狀態(tài),計算房費直接執(zhí)行收費,同時將顧客數(shù)加1。

3. 退房:此函數(shù)是再go_out函數(shù)中實現(xiàn)的。首先,輸入要退房的顧客的姓名和身份證號碼,再輸入該顧客的實際住的天數(shù),系統(tǒng)計算出顧客的費用。用switch函數(shù)根據(jù)房間等級和所住天數(shù)來判斷是要給顧客退費用還是顧客需要補交費用。

4. 查詢:此功能在inquire函數(shù)中實現(xiàn)。信息查詢分為房間信息查詢和顧客信息查詢。對顧客信息查詢,有兩種方式:按姓名查詢;按身份證號查詢。?通過查詢可以得知每個房間的信息和每個顧客的房間信息與預付費用。

四、課設實現(xiàn)

1.登陸

//登陸
void function::welcome() {
?? ?system("color 3E");
?? ?char name[4],pass[7];
?? ?cout<<"請輸入用戶名和密碼:"<<endl;
?? ?cin>>name;
?? ?cin>>pass;
?? ?while((strcmp(name,"123")!=0)||(strcmp(pass,"123")!=0)) {
?? ??? ?cout<<"用戶名或密碼輸入有誤,請重新輸入!"<<endl;
?? ??? ?cin>>name;
?? ??? ?cin>>pass;
?? ?}
?? ?cout<<endl;
?? ?cout<<endl;
?? ?cout<<" ? ? ? ? ? ? ? ? ? ? ---------------------------"<<endl;
?? ?cout<<" ? ? ? ? ? ? ? ? ? ? ?歡迎使用旅館住宿管理系統(tǒng)!"<<endl;
?? ?cout<<" ? ? ? ? ? ? ? ? ? ? ---------------------------"<<endl;
?? ?cout<<endl;
?? ?system("pause");
?? ?system("cls");
}

2.初始化房間

//初始化
void function::initial_room() {
?? ?int j;
?? ?int k=101;
?? ?for(j=0; j<20; j++) {
?? ??? ?room[j].number=k++;
?? ??? ?room[j].rad=1;
?? ??? ?room[j].price=100;
?? ??? ?room[j].state=0;
?? ?}
?? ?k=201;
?? ?for(j=20; j<40; j++) {
?? ??? ?room[j].number=k++;
?? ??? ?room[j].rad=2;
?? ??? ?room[j].price=200;
?? ??? ?room[j].state=0;
?? ?}
?? ?k=301;
?? ?for(j=40; j<60; j++) {
?? ??? ?room[j].number=k++;
?? ??? ?room[j].rad=3;
?? ??? ?room[j].price=300;
?? ??? ?room[j].state=0;
?? ?}
}
int main() {
?? ?char choice='1';
?? ?function m;
?? ?m.initial_room();?? ?//初始化60個房間
?? ?m.welcome();?? ?
?? ??? ??? ?//驗證
?? ?while(choice=='1') {
?? ??? ?m.menu();//功能
?? ??? ?cout<<endl;
?? ??? ?cout<<"1. 繼續(xù)使用 ? 2. 退出 "<<endl;
?? ??? ?cin>>choice;
?? ??? ?cout<<endl;
?? ?}
}

3.訂房

//訂房
void function::book_room() {
?? ?customer[i]=new Customer;
?? ?int room_kind,day;
?? ?cout<<"請您選擇預定房間類型:\n";
?? ?cout<<"1.單人間/天/100元\n2.雙人間/天/200元\n3.標準間/天/300元"<<endl;
?? ?cin>>room_kind;
?? ?cout<<"請輸入預定天數(shù)"<<endl;
?? ?cin>>day;
?? ?customer[i]->set_day(day);
?? ?switch(room_kind) {
?? ??? ??? ?int n;
?? ??? ?case 1:
?? ??? ??? ?cout<<"住房費用總共為: "<<day*100<<"元"<<endl;
?? ??? ??? ?for(n=0; n<20; n++) {?? ??? ??? ??? ??? ??? ??? ??? ?//從第一個級別的房間中查找一個空閑的房間
?? ??? ??? ??? ?if(room[n].state==0) {?? ??? ??? ??? ??? ??? ??? ?//state=0表示該住房沒有被預定的
?? ??? ??? ??? ??? ?cout<<"預定成功 ? 房間號碼為: "<<room[n].number<<endl;
?? ??? ??? ??? ??? ?room[n].state=1;
?? ??? ??? ??? ??? ?customer[i]->set_room_number(room[n].number);
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?case 2:
?? ??? ??? ?cout<<"住房費用總共為: "<<day*200<<" 元"<<endl;
?? ??? ??? ?for(n=20; n<40; n++) {
?? ??? ??? ??? ?if(room[n].state==0) {
?? ??? ??? ??? ??? ?cout<<"預定成功 ? 房間號碼為: "<<room[n].number<<endl;
?? ??? ??? ??? ??? ?room[n].state=1;
?? ??? ??? ??? ??? ?customer[i]->set_room_number(room[n].number);
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?case 3: {
?? ??? ??? ?cout<<"住房費用總共為: "<<day*300<<" 元"<<endl;
?? ??? ??? ?for(n=40; n<60; n++) {
?? ??? ??? ??? ?if(room[n].state==0) {
?? ??? ??? ??? ??? ?cout<<"預訂成功 ? 房間號碼為: "<<room[n].number<<endl;
?? ??? ??? ??? ??? ?room[n].state=1;
?? ??? ??? ??? ??? ?customer[i]->set_room_number(room[n].number);
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?default:
?? ??? ??? ?cout<<"選擇有誤"<<endl;
?? ??? ??? ?break;
?? ?}
?? ?i++; ?//住房的顧客數(shù)加1
}

4.入住

//入住
void function::go_in() {
?? ?char name1[10],id1[19];
?? ?int q,prepaid;
?? ?cout<<"該顧客是否已訂房 (1. 已訂 ? 2. 沒訂) "<<endl;
?? ?cin>>q;
?? ?if(q==1) {
?? ??? ?cout<<"請輸入顧客的姓名:"<<endl;
?? ??? ?cin>>name1;
?? ??? ?cout<<"請輸入顧客的身份證號碼:"<<endl;
?? ??? ?cin>>id1;
?? ??? ?//i:顧客人數(shù)
?? ??? ?for(int j=0; j<=i; j++) {
?? ??? ??? ?if((strcmp(customer[j]->get_name(),name1)==0)&&(strcmp(customer[j]->get_ID(),id1)==0)) {
?? ??? ??? ??? ?int num=customer[j]->get_room_number();
?? ??? ??? ??? ?cout<<"顧客"<<name1<<"入住 ?房間號碼為: "<<num<<endl;
?? ??? ??? ??? ?switch(num/100) {
?? ??? ??? ??? ??? ?case 6:
?? ??? ??? ??? ??? ??? ?prepaid=customer[j]->get_day()*100;
?? ??? ??? ??? ??? ??? ?customer[j]->set_prepaid(prepaid);
?? ??? ??? ??? ??? ??? ?cout<<"請收費用 "<<prepaid<<"元"<<endl;
?? ??? ??? ??? ??? ??? ?room[num%100-1].state=2; ? ? ? ? ? ? ? ? ?//修改房間狀態(tài)為入住狀態(tài)
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?case 7:
?? ??? ??? ??? ??? ??? ?prepaid=customer[j]->get_day()*200;
?? ??? ??? ??? ??? ??? ?customer[j]->set_prepaid(prepaid);
?? ??? ??? ??? ??? ??? ?cout<<"請收費用 "<<prepaid<<"元"<<endl;
?? ??? ??? ??? ??? ??? ?room[19+num%100].state=2;
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?case 8:
?? ??? ??? ??? ??? ??? ?prepaid=customer[j]->get_day()*300;
?? ??? ??? ??? ??? ??? ?customer[j]->set_prepaid(prepaid);
?? ??? ??? ??? ??? ??? ?cout<<"請收費用 "<<prepaid<<"元"<<endl;
?? ??? ??? ??? ??? ??? ?room[39+num%100].state=2;
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?break;
?? ??? ??? ?}
?? ??? ?}
?? ?} else {
?? ??? ?customer[i]=new Customer;
?? ??? ?int roomkind;
?? ??? ?int day;
?? ??? ?cout<<"請輸入要預定的天數(shù):"<<endl;
?? ??? ?cout<<"1.單人間/天/100元\n2.雙人間/天/200元\n3.標準間/天/300元"<<endl;
?? ??? ?cin>>roomkind;
?? ??? ?cout<<"請輸入住宿天數(shù):"<<endl;
?? ??? ?cin>>day;
?? ??? ?customer[i]->set_day(day);
?? ??? ?switch(roomkind) {
?? ??? ??? ??? ?int n;
?? ??? ??? ?case 1:
?? ??? ??? ??? ?prepaid=day*100;
?? ??? ??? ??? ?customer[i]->set_prepaid(prepaid);
?? ??? ??? ??? ?cout<<"請收費用 "<<prepaid<<"元"<<endl;
?? ??? ??? ??? ?for(n=0; n<20; n++) {
?? ??? ??? ??? ??? ?if(room[n].state==0) {
?? ??? ??? ??? ??? ??? ?cout<<"入住房間號碼為: "<<room[n].number<<endl;
?? ??? ??? ??? ??? ??? ?room[n].state=2;
?? ??? ??? ??? ??? ??? ?customer[i]->set_room_number(room[n].number);
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}
?? ??? ??? ??? ?break;
?? ??? ??? ?case 2:
?? ??? ??? ??? ?prepaid=day*200;
?? ??? ??? ??? ?customer[i]->set_prepaid(prepaid);
?? ??? ??? ??? ?cout<<"請收費用 "<<prepaid<<"元"<<endl;
?? ??? ??? ??? ?for(n=20; n<40; n++) {
?? ??? ??? ??? ??? ?if(room[n].state==0) {
?? ??? ??? ??? ??? ??? ?cout<<"入住房間號為: "<<room[n].number<<endl;
?? ??? ??? ??? ??? ??? ?room[n].state=2;
?? ??? ??? ??? ??? ??? ?customer[i]->set_room_number(room[n].number);
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}
?? ??? ??? ??? ?break;
?? ??? ??? ?case 3:
?? ??? ??? ??? ?prepaid=day*300;
?? ??? ??? ??? ?customer[i]->set_prepaid(prepaid);
?? ??? ??? ??? ?cout<<"請收費用 "<<prepaid<<"元"<<endl;
?? ??? ??? ??? ?for(n=40; n<60; n++) {
?? ??? ??? ??? ??? ?if(room[n].state==0) {
?? ??? ??? ??? ??? ??? ?cout<<"入住房間號為: "<<room[n].number<<endl;
?? ??? ??? ??? ??? ??? ?room[n].state=2;
?? ??? ??? ??? ??? ??? ?customer[i]->set_room_number(room[n].number);
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}
?? ??? ??? ??? ?break;
?? ??? ?}
?? ??? ?i++;
?? ?}
}

5.退房

//退房
void function::go_out() {
?? ?char name2[10],id2[19];
?? ?int room_number;
?? ?int day;//多或少天數(shù)
?? ?cout<<"請輸入要退房的顧客姓名和身份證號碼:"<<endl;
?? ?cin>>name2;
?? ?cin>>id2;
?? ?cout<<"請輸入該顧客實際所住天數(shù):"<<endl;
?? ?int day2;
?? ?cin>>day2;
?? ?int j;
?? ?for(j=0; j<i; j++) {
?? ??? ?if((strcmp(customer[j]->get_name(),name2)==0)&&(strcmp(customer[j]->get_ID(),id2)==0)) {
?? ??? ??? ?room_number=customer[j]->get_room_number();
?? ??? ??? ?int w;
?? ??? ??? ?w=room_number/100;
?? ??? ??? ?int day1;
?? ??? ??? ?day1=customer[j]->get_day();
?? ??? ??? ?day=day1-day2;
?? ??? ??? ?switch(w) {
?? ??? ??? ??? ?case 1:
?? ??? ??? ??? ??? ?cout<<"顧客的房間號是"<<room_number<<" :為單人間,每天100元"<<endl;
?? ??? ??? ??? ??? ?cout<<"該顧客預付了房費 "<<customer[j]->get_prepaid()<<"元, 實際消費 "<<day2*100<<"元"<<endl;
?? ??? ??? ??? ??? ?cout<<endl;
?? ??? ??? ??? ??? ?if(day>0)
?? ??? ??? ??? ??? ??? ?cout<<"請退給該顧客 "<<day*100<<" 元"<<endl;
?? ??? ??? ??? ??? ?if(day<0)
?? ??? ??? ??? ??? ??? ?cout<<"請補收該顧客住房費 "<<-day*100<<" 元"<<endl;
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?case 2:
?? ??? ??? ??? ??? ?cout<<"顧客的房間號是"<<room_number<<" :為雙人間,每天200元"<<endl;
?? ??? ??? ??? ??? ?cout<<"該顧客預付了房費 "<<customer[j]->get_prepaid()<<"元, 實際消費 "<<day2*200<<"元"<<endl;
?? ??? ??? ??? ??? ?cout<<endl;
?? ??? ??? ??? ??? ?if(day>0)
?? ??? ??? ??? ??? ??? ?cout<<"請退給該顧客 "<<day*200<<" 元"<<endl;
?? ??? ??? ??? ??? ?if(day<0)
?? ??? ??? ??? ??? ??? ?cout<<"請補收該顧客住房費 "<<-day*200<<" 元"<<endl;
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?case 3:
?? ??? ??? ??? ??? ?cout<<"顧客的房間號是"<<room_number<<" ? :為標準間,每天300元"<<endl;
?? ??? ??? ??? ??? ?cout<<"該顧客預付了房費 "<<customer[j]->get_prepaid()<<"元, 實際消費 "<<day2*300<<"元"<<endl;
?? ??? ??? ??? ??? ?cout<<endl;
?? ??? ??? ??? ??? ?if(day>0)
?? ??? ??? ??? ??? ??? ?cout<<"請退給該顧客 "<<day*300<<" 元"<<endl;
?? ??? ??? ??? ??? ?if(day<0)
?? ??? ??? ??? ??? ??? ?cout<<"請補收該顧客住房費 "<<-day*300<<" 元"<<endl;
?? ??? ??? ??? ??? ?break;
?? ??? ??? ?}
?? ??? ??? ?cout<<endl;
?? ??? ??? ?cout<<"確認退房,請按1: "<<endl;
?? ??? ??? ?char v;
?? ??? ??? ?cin>>v;
?? ??? ??? ?if(v=='1') {
?? ??? ??? ??? ?for(int k=0; k<60; k++) {
?? ??? ??? ??? ??? ?if(room[k].number==customer[j]->get_room_number())
?? ??? ??? ??? ??? ??? ?room[k].state=0;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?i--;
?? ??? ??? ??? ?for(; j<i; j++) {
?? ??? ??? ??? ??? ?customer[j]=customer[j+1];
?? ??? ??? ??? ?}
?? ??? ??? ??? ?delete customer[i];
?? ??? ??? ?}
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?cout<<"無此顧客信息"<<endl;
?? ??? ??? ?break;
?? ??? ?}
?? ?}
}

6.查詢

//查詢
void function::inquire() {
?? ?char option;
?? ?cout<<"1.房間信息查詢, 2.顧客信息查詢: "<<endl;
?? ?cin>>option;
?? ?if(option=='1') {
?? ??? ?int j;
?? ??? ?int k=0;
?? ??? ?cout<<endl;
?? ??? ?cout<<"空房間:"<<endl;
?? ??? ?for(j=0; j<60; j++) {
?? ??? ??? ?if(room[j].state==0) {
?? ??? ??? ??? ?if(k%10==0) cout<<endl;//一行十個
?? ??? ??? ??? ?cout<<room[j].number<<'\t';
?? ??? ??? ??? ?k++;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?cout<<endl;
?? ??? ?cout<<endl;
?? ??? ?k=0;
?? ??? ?cout<<"已預訂房間:"<<endl;
?? ??? ?for(j=0; j<60; j++) {
?? ??? ??? ?if(room[j].state==1) {
?? ??? ??? ??? ?if(k%10==0) cout<<endl;
?? ??? ??? ??? ?cout<<room[j].number<<'\t';
?? ??? ??? ??? ?k++;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?k=0;
?? ??? ?cout<<endl;
?? ??? ?cout<<endl;
?? ??? ?cout<<"已入住房間:"<<endl;
?? ??? ?for(j=0; j<60; j++) {
?? ??? ??? ?if(room[j].state==2) {
?? ??? ??? ??? ?if(k%10==0) cout<<endl;
?? ??? ??? ??? ?cout<<room[j].number<<'\t';
?? ??? ??? ??? ?k++;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?cout<<endl;
?? ??? ?cout<<endl;
?? ?} else if(option=='2') {
?? ??? ?cout<<"1.按姓名查詢, 2.按身份證查詢: "<<endl;
?? ??? ?char option;
?? ??? ?cin>>option;
?? ??? ?if(option=='1') {
?? ??? ??? ?char name3[10];
?? ??? ??? ?cout<<"請輸入顧客的姓名: ";
?? ??? ??? ?cin>>name3;
?? ??? ??? ?for(int j=0; j<=i; j++) {
?? ??? ??? ??? ?if(strcmp(customer[j]->get_name(),name3)==0) {
?? ??? ??? ??? ??? ?cout<<name3<<"的信息如下:"<<endl;
?? ??? ??? ??? ??? ?cout<<"\t"<<"房間號: "<<customer[j]->get_room_number()<<endl;
?? ??? ??? ??? ??? ?cout<<"\t"<<"預付費用: "<<customer[j]->get_prepaid()<<endl;
?? ??? ??? ??? ??? ?break;?
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?cout<<"無此顧客信息"<<endl;
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ?}
?? ??? ?if(option=='2') {
?? ??? ??? ?char id3[10];
?? ??? ??? ?cout<<"請輸入顧客的身份證號碼: "<<endl;
?? ??? ??? ?cin>>id3;
?? ??? ??? ?for(int j=0; j<=i; j++) {
?? ??? ??? ??? ?if(strcmp(customer[j]->get_ID(),id3)==0) {
?? ??? ??? ??? ??? ?cout<<customer[j]->get_name()<<"的房間信息:"<<endl;
?? ??? ??? ??? ??? ?cout<<"\t"<<"房間號: "<<customer[j]->get_room_number()<<endl;
?? ??? ??? ??? ??? ?cout<<"\t"<<"預付房費: "<<customer[j]->get_prepaid()<<endl;
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?cout<<"無此顧客信息"<<endl;
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ?}
?? ?}
}

(1)房間信息查詢

(2)顧客信息查詢

完整的放這嘍

//賬號為123?
//密碼為123?
#include<iostream>
#include<cstdlib>
#include<cstring>
using namespace std;
int i=0;
struct Room {
?? ?int number;
?? ?int rad;?
?? ?int price;
?? ?int state;
};
class Customer {
?? ?public:
?? ??? ?Customer();
?? ??? ?void set_name(char *n) {
?? ??? ??? ?strcpy(name,n);
?? ??? ?}
?? ??? ?void set_ID(char *p) {
?? ??? ??? ?strcpy(ID,p);
?? ??? ?}
?? ??? ?void set_room_number(int n) {
?? ??? ??? ?room_number=n;
?? ??? ?}
?? ??? ?void set_day(int d) {
?? ??? ??? ?day=d;
?? ??? ?}
?? ??? ?void set_prepaid(int p) {
?? ??? ??? ?prepaid=p;
?? ??? ?}
?? ??? ?char *get_name() {
?? ??? ??? ?return name;
?? ??? ?}
?? ??? ?char *get_ID() {
?? ??? ??? ?return ID;
?? ??? ?}
?? ??? ?int ?get_room_number() {
?? ??? ??? ?return room_number;
?? ??? ?}
?? ??? ?int ?get_day() {
?? ??? ??? ?return day;
?? ??? ?}
?? ??? ?int ?get_prepaid() {
?? ??? ??? ?return prepaid;
?? ??? ?}
?? ??? ?virtual ~Customer();
?? ?private:
?? ??? ?char name[10],ID[19];
?? ??? ?int ?room_number;
?? ??? ?int ?prepaid;
?? ??? ?int ?change;
?? ??? ?int ?day;
};
Customer::Customer() {//構造函數(shù)
?? ?cout<<"請您輸入顧客的姓名"<<endl;
?? ?cin>>name;
?? ?cout<<"請您輸入顧客的身份證號碼"<<endl;
?? ?cin>>ID;
?? ?prepaid=day=0;
}
Customer::~Customer() {//析構函數(shù)
?? ?cout<<"該顧客退房成功!"<<endl;
}
Room room[60];
Customer *customer[60];
?
class function
{
?? ?public:
?? ?void initial_room();
?? ?void welcome();
?? ?void menu();
?? ?void book_room();
?? ?void go_in();
?? ?void go_out();
?? ?void inquire();
?? ?void out();?? ?
};
int main() {
?? ?char choice='1';
?? ?function m;
?? ?m.initial_room();?? ?//初始化60個房間
?? ?m.welcome();?? ?
?? ??? ??? ?//驗證
?? ?while(choice=='1') {
?? ??? ?m.menu();//功能
?? ??? ?cout<<endl;
?? ??? ?cout<<"1. 繼續(xù)使用 ? 2. 退出 "<<endl;
?? ??? ?cin>>choice;
?? ??? ?cout<<endl;
?? ?}
}
//登陸
void function::welcome() {
?? ?system("color 3E");
?? ?char name[4],pass[7];
?? ?cout<<"請輸入用戶名和密碼:"<<endl;
?? ?cin>>name;
?? ?cin>>pass;
?? ?while((strcmp(name,"123")!=0)||(strcmp(pass,"123")!=0)) {
?? ??? ?cout<<"用戶名或密碼輸入有誤,請重新輸入!"<<endl;
?? ??? ?cin>>name;
?? ??? ?cin>>pass;
?? ?}
?? ?cout<<endl;
?? ?cout<<endl;
?? ?cout<<" ? ? ? ? ? ? ? ? ? ? ---------------------------"<<endl;
?? ?cout<<" ? ? ? ? ? ? ? ? ? ? ?歡迎使用旅館住宿管理系統(tǒng)!"<<endl;
?? ?cout<<" ? ? ? ? ? ? ? ? ? ? ---------------------------"<<endl;
?? ?cout<<endl;
?? ?system("pause");
?? ?system("cls");
}
void function::menu() {
?? ?function n;
?? ?char x;
?? ?cout<<"\t\t請選擇功能: "<<endl;
?? ?cout<<" \t ? 1.預定 ?\t2.入住 ?"<<endl;
?? ?cout<<" \t ? 3.退房 ?\t4.查詢"<<endl;
?? ?cout<<" ? ?\t ? 5.退出 ?\t"<<endl;
?? ?cin>>x;
?? ?switch(x) {
?? ??? ?case '1':
?? ??? ??? ?n.book_room();
?? ??? ??? ?system("pause");
?? ??? ??? ?system("cls");
?? ??? ??? ?break;
?? ??? ?case '2':
?? ??? ??? ?n.go_in();
?? ??? ??? ?system("pause");
?? ??? ??? ?system("cls");
?? ??? ??? ?break;
?? ??? ?case '3':
?? ??? ??? ?n.go_out();
?? ??? ??? ?system("pause");
?? ??? ??? ?system("cls");
?? ??? ??? ?break;
?? ??? ?case '4':
?? ??? ??? ?n.inquire();
?? ??? ??? ?system("pause");
?? ??? ??? ?system("cls");
?? ??? ??? ?break;
?? ??? ?case '5':
?? ??? ??? ?n.out();
?? ??? ??? ?break;
?? ??? ?default:
?? ??? ??? ?cout<<"輸入有誤,請重新輸入"<<endl;
?? ??? ??? ?cin>>x;
?? ?}
}
//訂房
void function::book_room() {
?? ?customer[i]=new Customer;
?? ?int room_kind,day;
?? ?cout<<"請您選擇預定房間類型:\n";
?? ?cout<<"1.單人間/天/100元\n2.雙人間/天/200元\n3.標準間/天/300元"<<endl;
?? ?cin>>room_kind;
?? ?cout<<"請輸入預定天數(shù)"<<endl;
?? ?cin>>day;
?? ?customer[i]->set_day(day);
?? ?switch(room_kind) {
?? ??? ??? ?int n;
?? ??? ?case 1:
?? ??? ??? ?cout<<"住房費用總共為: "<<day*100<<"元"<<endl;
?? ??? ??? ?for(n=0; n<20; n++) {?? ?//從第一個級別的房間中查找一個空閑的房間
?? ??? ??? ??? ?if(room[n].state==0) {???//state=0表示該住房沒有被預定的
?? ??? ??? ??? ??? ?cout<<"預定成功 ? 房間號碼為: "<<room[n].number<<endl;
?? ??? ??? ??? ??? ?room[n].state=1;
?? ??? ??? ??? ??? ?customer[i]->set_room_number(room[n].number);
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?case 2:
?? ??? ??? ?cout<<"住房費用總共為: "<<day*200<<" 元"<<endl;
?? ??? ??? ?for(n=20; n<40; n++) {
?? ??? ??? ??? ?if(room[n].state==0) {
?? ??? ??? ??? ??? ?cout<<"預定成功 ? 房間號碼為: "<<room[n].number<<endl;
?? ??? ??? ??? ??? ?room[n].state=1;
?? ??? ??? ??? ??? ?customer[i]->set_room_number(room[n].number);
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?case 3: {
?? ??? ??? ?cout<<"住房費用總共為: "<<day*300<<" 元"<<endl;
?? ??? ??? ?for(n=40; n<60; n++) {
?? ??? ??? ??? ?if(room[n].state==0) {
?? ??? ??? ??? ??? ?cout<<"預訂成功 ? 房間號碼為: "<<room[n].number<<endl;
?? ??? ??? ??? ??? ?room[n].state=1;
?? ??? ??? ??? ??? ?customer[i]->set_room_number(room[n].number);
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ??? ?break;
?? ??? ?}
?? ??? ?default:
?? ??? ??? ?cout<<"選擇有誤"<<endl;
?? ??? ??? ?break;
?? ?}
?? ?i++; ?//住房的顧客數(shù)加1
}
//入住
void function::go_in() {
?? ?char name1[10],id1[19];
?? ?int q,prepaid;
?? ?cout<<"該顧客是否已訂房 (1. 已訂 ? 2. 沒訂) "<<endl;
?? ?cin>>q;
?? ?if(q==1) {
?? ??? ?cout<<"請輸入顧客的姓名:"<<endl;
?? ??? ?cin>>name1;
?? ??? ?cout<<"請輸入顧客的身份證號碼:"<<endl;
?? ??? ?cin>>id1;
?? ??? ?//i:顧客人數(shù)
?? ??? ?for(int j=0; j<=i; j++) {
?? ??? ??? ?if((strcmp(customer[j]->get_name(),name1)==0)&&(strcmp(customer[j]->get_ID(),id1)==0)) {
?? ??? ??? ??? ?int num=customer[j]->get_room_number();
?? ??? ??? ??? ?cout<<"顧客"<<name1<<"入住 ?房間號碼為: "<<num<<endl;
?? ??? ??? ??? ?switch(num/100) {
?? ??? ??? ??? ??? ?case 6:
?? ??? ??? ??? ??? ??? ?prepaid=customer[j]->get_day()*100;
?? ??? ??? ??? ??? ??? ?customer[j]->set_prepaid(prepaid);
?? ??? ??? ??? ??? ??? ?cout<<"請收費用 "<<prepaid<<"元"<<endl;
?? ??? ??? ??? ??? ??? ?room[num%100-1].state=2; ? ? ? ? ? ? ? ? ?//修改房間狀態(tài)為入住狀態(tài)
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?case 7:
?? ??? ??? ??? ??? ??? ?prepaid=customer[j]->get_day()*200;
?? ??? ??? ??? ??? ??? ?customer[j]->set_prepaid(prepaid);
?? ??? ??? ??? ??? ??? ?cout<<"請收費用 "<<prepaid<<"元"<<endl;
?? ??? ??? ??? ??? ??? ?room[19+num%100].state=2;
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?case 8:
?? ??? ??? ??? ??? ??? ?prepaid=customer[j]->get_day()*300;
?? ??? ??? ??? ??? ??? ?customer[j]->set_prepaid(prepaid);
?? ??? ??? ??? ??? ??? ?cout<<"請收費用 "<<prepaid<<"元"<<endl;
?? ??? ??? ??? ??? ??? ?room[39+num%100].state=2;
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?break;
?? ??? ??? ?}
?? ??? ?}
?? ?} else {
?? ??? ?customer[i]=new Customer;
?? ??? ?int roomkind;
?? ??? ?int day;
?? ??? ?cout<<"請輸入要預定的天數(shù):"<<endl;
?? ??? ?cout<<"1.單人間/天/100元\n2.雙人間/天/200元\n3.標準間/天/300元"<<endl;
?? ??? ?cin>>roomkind;
?? ??? ?cout<<"請輸入住宿天數(shù):"<<endl;
?? ??? ?cin>>day;
?? ??? ?customer[i]->set_day(day);
?? ??? ?switch(roomkind) {
?? ??? ??? ??? ?int n;
?? ??? ??? ?case 1:
?? ??? ??? ??? ?prepaid=day*100;
?? ??? ??? ??? ?customer[i]->set_prepaid(prepaid);
?? ??? ??? ??? ?cout<<"請收費用 "<<prepaid<<"元"<<endl;
?? ??? ??? ??? ?for(n=0; n<20; n++) {
?? ??? ??? ??? ??? ?if(room[n].state==0) {
?? ??? ??? ??? ??? ??? ?cout<<"入住房間號碼為: "<<room[n].number<<endl;
?? ??? ??? ??? ??? ??? ?room[n].state=2;
?? ??? ??? ??? ??? ??? ?customer[i]->set_room_number(room[n].number);
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}
?? ??? ??? ??? ?break;
?? ??? ??? ?case 2:
?? ??? ??? ??? ?prepaid=day*200;
?? ??? ??? ??? ?customer[i]->set_prepaid(prepaid);
?? ??? ??? ??? ?cout<<"請收費用 "<<prepaid<<"元"<<endl;
?? ??? ??? ??? ?for(n=20; n<40; n++) {
?? ??? ??? ??? ??? ?if(room[n].state==0) {
?? ??? ??? ??? ??? ??? ?cout<<"入住房間號為: "<<room[n].number<<endl;
?? ??? ??? ??? ??? ??? ?room[n].state=2;
?? ??? ??? ??? ??? ??? ?customer[i]->set_room_number(room[n].number);
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}
?? ??? ??? ??? ?break;
?? ??? ??? ?case 3:
?? ??? ??? ??? ?prepaid=day*300;
?? ??? ??? ??? ?customer[i]->set_prepaid(prepaid);
?? ??? ??? ??? ?cout<<"請收費用 "<<prepaid<<"元"<<endl;
?? ??? ??? ??? ?for(n=40; n<60; n++) {
?? ??? ??? ??? ??? ?if(room[n].state==0) {
?? ??? ??? ??? ??? ??? ?cout<<"入住房間號為: "<<room[n].number<<endl;
?? ??? ??? ??? ??? ??? ?room[n].state=2;
?? ??? ??? ??? ??? ??? ?customer[i]->set_room_number(room[n].number);
?? ??? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ??? ?}
?? ??? ??? ??? ?}
?? ??? ??? ??? ?break;
?? ??? ?}
?? ??? ?i++;
?? ?}
}
//退房
void function::go_out() {
?? ?char name2[10],id2[19];
?? ?int room_number;
?? ?int day;//多或少天數(shù)
?? ?cout<<"請輸入要退房的顧客姓名和身份證號碼:"<<endl;
?? ?cin>>name2;
?? ?cin>>id2;
?? ?cout<<"請輸入該顧客實際所住天數(shù):"<<endl;
?? ?int day2;
?? ?cin>>day2;
?? ?int j;
?? ?for(j=0; j<i; j++) {
?? ??? ?if((strcmp(customer[j]->get_name(),name2)==0)&&(strcmp(customer[j]->get_ID(),id2)==0)) {
?? ??? ??? ?room_number=customer[j]->get_room_number();
?? ??? ??? ?int w;
?? ??? ??? ?w=room_number/100;
?? ??? ??? ?int day1;
?? ??? ??? ?day1=customer[j]->get_day();
?? ??? ??? ?day=day1-day2;
?? ??? ??? ?switch(w) {
?? ??? ??? ??? ?case 1:
?? ??? ??? ??? ??? ?cout<<"顧客的房間號是"<<room_number<<" :為單人間,每天100元"<<endl;
?? ??? ??? ??? ??? ?cout<<"該顧客預付了房費 "<<customer[j]->get_prepaid()<<"元, 實際消費 "<<day2*100<<"元"<<endl;
?? ??? ??? ??? ??? ?cout<<endl;
?? ??? ??? ??? ??? ?if(day>0)
?? ??? ??? ??? ??? ??? ?cout<<"請退給該顧客 "<<day*100<<" 元"<<endl;
?? ??? ??? ??? ??? ?if(day<0)
?? ??? ??? ??? ??? ??? ?cout<<"請補收該顧客住房費 "<<-day*100<<" 元"<<endl;
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?case 2:
?? ??? ??? ??? ??? ?cout<<"顧客的房間號是"<<room_number<<" :為雙人間,每天200元"<<endl;
?? ??? ??? ??? ??? ?cout<<"該顧客預付了房費 "<<customer[j]->get_prepaid()<<"元, 實際消費 "<<day2*200<<"元"<<endl;
?? ??? ??? ??? ??? ?cout<<endl;
?? ??? ??? ??? ??? ?if(day>0)
?? ??? ??? ??? ??? ??? ?cout<<"請退給該顧客 "<<day*200<<" 元"<<endl;
?? ??? ??? ??? ??? ?if(day<0)
?? ??? ??? ??? ??? ??? ?cout<<"請補收該顧客住房費 "<<-day*200<<" 元"<<endl;
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?case 3:
?? ??? ??? ??? ??? ?cout<<"顧客的房間號是"<<room_number<<" ? :為標準間,每天300元"<<endl;
?? ??? ??? ??? ??? ?cout<<"該顧客預付了房費 "<<customer[j]->get_prepaid()<<"元, 實際消費 "<<day2*300<<"元"<<endl;
?? ??? ??? ??? ??? ?cout<<endl;
?? ??? ??? ??? ??? ?if(day>0)
?? ??? ??? ??? ??? ??? ?cout<<"請退給該顧客 "<<day*300<<" 元"<<endl;
?? ??? ??? ??? ??? ?if(day<0)
?? ??? ??? ??? ??? ??? ?cout<<"請補收該顧客住房費 "<<-day*300<<" 元"<<endl;
?? ??? ??? ??? ??? ?break;
?? ??? ??? ?}
?? ??? ??? ?cout<<endl;
?? ??? ??? ?cout<<"確認退房,請按1: "<<endl;
?? ??? ??? ?char v;
?? ??? ??? ?cin>>v;
?? ??? ??? ?if(v=='1') {
?? ??? ??? ??? ?for(int k=0; k<60; k++) {
?? ??? ??? ??? ??? ?if(room[k].number==customer[j]->get_room_number())
?? ??? ??? ??? ??? ??? ?room[k].state=0;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?i--;
?? ??? ??? ??? ?for(; j<i; j++) {
?? ??? ??? ??? ??? ?customer[j]=customer[j+1];
?? ??? ??? ??? ?}
?? ??? ??? ??? ?delete customer[i];
?? ??? ??? ?}
?? ??? ?}
?? ??? ?else
?? ??? ?{
?? ??? ??? ?cout<<"無此顧客信息"<<endl;
?? ??? ??? ?break;
?? ??? ?}
?? ?}
}
//查詢
void function::inquire() {
?? ?char option;
?? ?cout<<"1.房間信息查詢, 2.顧客信息查詢: "<<endl;
?? ?cin>>option;
?? ?if(option=='1') {
?? ??? ?int j;
?? ??? ?int k=0;
?? ??? ?cout<<endl;
?? ??? ?cout<<"空房間:"<<endl;
?? ??? ?for(j=0; j<60; j++) {
?? ??? ??? ?if(room[j].state==0) {
?? ??? ??? ??? ?if(k%10==0) cout<<endl;//一行十個
?? ??? ??? ??? ?cout<<room[j].number<<'\t';
?? ??? ??? ??? ?k++;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?cout<<endl;
?? ??? ?cout<<endl;
?? ??? ?k=0;
?? ??? ?cout<<"已預訂房間:"<<endl;
?? ??? ?for(j=0; j<60; j++) {
?? ??? ??? ?if(room[j].state==1) {
?? ??? ??? ??? ?if(k%10==0) cout<<endl;
?? ??? ??? ??? ?cout<<room[j].number<<'\t';
?? ??? ??? ??? ?k++;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?k=0;
?? ??? ?cout<<endl;
?? ??? ?cout<<endl;
?? ??? ?cout<<"已入住房間:"<<endl;
?? ??? ?for(j=0; j<60; j++) {
?? ??? ??? ?if(room[j].state==2) {
?? ??? ??? ??? ?if(k%10==0) cout<<endl;
?? ??? ??? ??? ?cout<<room[j].number<<'\t';
?? ??? ??? ??? ?k++;
?? ??? ??? ?}
?? ??? ?}
?? ??? ?cout<<endl;
?? ??? ?cout<<endl;
?? ?} else if(option=='2') {
?? ??? ?cout<<"1.按姓名查詢, 2.按身份證查詢: "<<endl;
?? ??? ?char option;
?? ??? ?cin>>option;
?? ??? ?if(option=='1') {
?? ??? ??? ?char name3[10];
?? ??? ??? ?cout<<"請輸入顧客的姓名: ";
?? ??? ??? ?cin>>name3;
?? ??? ??? ?for(int j=0; j<=i; j++) {
?? ??? ??? ??? ?if(strcmp(customer[j]->get_name(),name3)==0) {
?? ??? ??? ??? ??? ?cout<<name3<<"的信息如下:"<<endl;
?? ??? ??? ??? ??? ?cout<<"\t"<<"房間號: "<<customer[j]->get_room_number()<<endl;
?? ??? ??? ??? ??? ?cout<<"\t"<<"預付費用: "<<customer[j]->get_prepaid()<<endl;
?? ??? ??? ??? ??? ?break;?
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?cout<<"無此顧客信息"<<endl;
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ?}
?? ??? ?if(option=='2') {
?? ??? ??? ?char id3[10];
?? ??? ??? ?cout<<"請輸入顧客的身份證號碼: "<<endl;
?? ??? ??? ?cin>>id3;
?? ??? ??? ?for(int j=0; j<=i; j++) {
?? ??? ??? ??? ?if(strcmp(customer[j]->get_ID(),id3)==0) {
?? ??? ??? ??? ??? ?cout<<customer[j]->get_name()<<"的房間信息:"<<endl;
?? ??? ??? ??? ??? ?cout<<"\t"<<"房間號: "<<customer[j]->get_room_number()<<endl;
?? ??? ??? ??? ??? ?cout<<"\t"<<"預付房費: "<<customer[j]->get_prepaid()<<endl;
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ??? ?else
?? ??? ??? ??? ?{
?? ??? ??? ??? ??? ?cout<<"無此顧客信息"<<endl;
?? ??? ??? ??? ??? ?break;
?? ??? ??? ??? ?}
?? ??? ??? ?}
?? ??? ?}
?? ?}
}
//初始化
void function::initial_room() {
?? ?int j;
?? ?int k=101;
?? ?for(j=0; j<20; j++) {
?? ??? ?room[j].number=k++;
?? ??? ?room[j].rad=1;
?? ??? ?room[j].price=100;
?? ??? ?room[j].state=0;
?? ?}
?? ?k=201;
?? ?for(j=20; j<40; j++) {
?? ??? ?room[j].number=k++;
?? ??? ?room[j].rad=2;
?? ??? ?room[j].price=200;
?? ??? ?room[j].state=0;
?? ?}
?? ?k=301;
?? ?for(j=40; j<60; j++) {
?? ??? ?room[j].number=k++;
?? ??? ?room[j].rad=3;
?? ??? ?room[j].price=300;
?? ??? ?room[j].state=0;
?? ?}
}
void function::out()
{
?? ?return;
}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

相關文章

最新評論