賓館客房管理系統

#include<iostream> 
#include<iomanip> 
#include<string> 
#include <fstream>
using namespace std; 
const int m=100; 
struct Room{  
int id;            //房間號  
int degree;        //客房等級  
int type;          //客房類型  
int floor;         //客房樓層  
int number;        //客房數目 
}; 
class Menu{  
public:    
int MainMenu();  
private:  
};   
int Menu::MainMenu(){  
system("cls");   
cout<<"                  ┌◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆┐"<<endl;      
cout<<"                  |      歡迎使用簡明客戶管理系統      |"<<endl;      
cout<<"                   ------------------------------------"<<endl;       
cout<<"                  |                                    |"<<endl;      
cout<<"                  |          1.客人入住信息錄入        |"<<endl;   
cout<<"                  |                                    |"<<endl;     
cout<<"                  |          2.顯示樓層客房信息        |"<<endl;      
cout<<"                  |                                    |"<<endl;      
cout<<"                  |          3.查詢客人入住狀況        |"<<endl;   
cout<<"                  |                                    |"<<endl;  
cout<<"                  |          4.修改房間押金            |"<<endl;   
cout<<"                  |                                    |"<<endl;   
cout<<"                  |          5.修改客人信息            |"<<endl;   
cout<<"                  |                                    |"<<endl;   
cout<<"                  |          6.統計並顯示收入          |"<<endl;               
cout<<"                  |                                    |"<<endl;  
cout<<"                  |          7.客房入住量排序          |"<<endl;
cout<<"                  |                                    |"<<endl; 
cout<<"                  |          8.退出程序                |"<<endl;
cout<<"                  |                                    |"<<endl;
cout<<"                  └◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆◆┘"<<endl; 
cout<<"                                                        "<<endl;
cout<<"                             請選擇(1-8):              "<<endl;
int select;
cin>>select;   
while(select<1 || select>8){    
cout<<"選擇錯誤!請從新選擇(1-8):";    
cin.clear();  //當輸入字符,清空流錯誤狀態    
cin.sync();  //清空數據流    
cin>>select;  
}   
return select; 
} 
class Customer{  
friend ostream &operator<<(ostream &os,Customer &cu); 
private:  
Menu myMenu;   
    string name;       //客人姓名  
int date;          //入住時間  
int day;           //入住期限  
int money;         //入住押金  
int everydaymoney; //每日租金  
Room room;   //客房信息 
public:  
Customer();  
Customer(string na, int dat, int da, int mo, int emon, int idn, int deg, int ty, int fl, int nu);  
string getname(){   
return name;  
}  
void setname(string na){   
name=na;  
}  
int getdate(){   
return date;  
}  
void setdate(int dat){   
date=dat;  
}  
int getday(){   
return day;  
} 
void setday(int da){   
day=da;  
}  
int getmoney(){   
return money;  
}  
void setmoney(int mon){   
money=mon;  
}  
int geteverydaymoney(){   
return everydaymoney;  
}  
void seteverdaymoney(int emon){   
everydaymoney=emon;  
}  
Room setroom(){   
return room;  
}  
void getroom(Room ro){   
room=ro;  
}  
void run();  
void input();       //建立表單  
int readIn();       //文件讀入  
void alter();       //修改信息  
void findByfloor(); //按樓層查找  
void changemoney(); //修改押金  
void show();        //顯示客戶入住狀況  
void print();       //統計並顯示收入 
void rank();        //客房類型入住量排序
}
customer[m];  
Customer::Customer(){  
name="#";  
date=0;  
day=0;  
money=0;  
everydaymoney=0;  
room.id=0;  
room.floor=0;  
room.degree=0;  
room.number=0;  
room.type=0; 
}  
Customer::Customer(string na, int dat, int da, int mo, int emon, int idn, int deg, int ty, int fl, int nu){  
name=na;
date=dat;  
day=da;  
money=mo;  
everydaymoney=emon;  
room.id=idn;  
room.degree=deg;  
room.type=ty;  
room.floor=fl;  
room.number=nu; 
}    
void Customer::input(){                  //客戶信息錄入  
int n;  
cout<<"請輸入入住人數"<<endl;  
cin>>room.number;  
cout<<endl;  
for(int i=0;i<room.number;i++){   
cout<<"這是第"<<i+1<<"個客戶的信息"<<endl;   
cout<<"輸入客人姓名:";   
cin>>customer[i].name;   
cout<<"入住時間(年/月/日):";   
cin>>customer[i].date;   
cout<<"入住期限:";   
cin>>customer[i].day;   
cout<<"入住押金:";   
cin>>customer[i].money;   
cout<<"每日租金:";   
cin>>customer[i].everydaymoney;   
cout<<"房間號:";   
cin>>customer[i].room.id;   
cout<<"房間等級(1-經濟 2-標準 3-豪華):";   
cin>>customer[i].room.degree;   
cout<<"房間類型(1-單人 2-雙人 3-三人):";   
cin>>customer[i].room.type;   
cout<<"樓層:";   
cin>>customer[i].room.floor;   
cout<<endl; 
}  
cout<<"輸入的信息爲:"<<endl;  
for(int i=0;i<room.number;i++){   
cout<<"客人姓名"<<customer[i].name;   
cout<<"\t入住時間:"<<customer[i].date;   
cout<<"\t入住期限:"<<customer[i].day;   
cout<<"\t入住押金:"<<customer[i].money;   
cout<<"\t每日租金:"<<customer[i].everydaymoney;   
cout<<"\t房間號:"<<customer[i].room.id;   
cout<<"\t房間等級:";   
if(customer[i].room.degree==1)    
cout<<"經濟間";   
else{    
if(customer[i].room.degree==2)     
cout<<"標準間";    
else{     
if(customer[i].room.degree==3)      
cout<<"豪華間";    
}   
}   
cout<<"\t房間類型:";   
if(customer[i].room.type==1)    
cout<<"單人間";   
else{    
if(customer[i].room.type==2)     
cout<<"雙人間";    
else{     
if(customer[i].room.type==3)      
cout<<"三人間";    
}   
}   
cout<<"\t樓層:"<<customer[i].room.floor;   
cout<<endl;  
}  
ofstream os("customer.txt",ios_base::out|ios_base::binary);  //建立、打開文件  
for(n=0;n<room.number;n++){   
os.write( reinterpret_cast<char*>(&(customer[n])),sizeof(Customer) );  //導出文件  
}  
os.close();  //關閉文件 
}  
int Customer::readIn(){                 //文件讀入  
int i,n;  
ifstream is("customer.txt",ios_base::in|ios_base::binary);
if(!is){   
cout<<"打開失敗"<<endl;   
return 0;  
}  
for(i=0;is.read( reinterpret_cast<char *>(customer+i) , sizeof(Customer) );i++)  
room.number=i;  
cout<<"導入的表單:"<<endl;  
for(n=0;n<room.number;n++){  
cout<<"客人姓名"<<customer[i].name;   
cout<<"入住時間:"<<customer[i].date;   
cout<<"入住期限:"<<customer[i].day;   
cout<<"入住押金:"<<customer[i].money;   
cout<<"每日租金:"<<customer[i].everydaymoney;   
cout<<"房間號:"<<customer[i].room.id;   
cout<<"房間等級:"<<customer[i].room.degree;   
cout<<"房間類型:"<<customer[i].room.type;   
cout<<"樓層:"<<customer[i].room.floor;  
}  
return 1; 
}  
void Customer::alter(){               //修改客戶信息  
int mark = 0;      //設置標記  
int i,m;  
string x;  
cout<<"請輸入客戶名:";  
do{   
cin>>x;   
cout<<endl;   
for(i=0;i<room.number;i++){    
if(customer[i].name==x){     
mark = 1;     
cout<<"客人姓名"<<customer[i].name;           
cout<<"\t入住時間:"<<customer[i].date;           
cout<<"\t入住期限:"<<customer[i].day;           
cout<<"\t入住押金:"<<customer[i].money;           
cout<<"\t每日租金:"<<customer[i].everydaymoney;           
cout<<"\t房間號:"<<customer[i].room.id;           
cout<<"\t房間等級:";     
if(customer[i].room.degree==1)             
cout<<"經濟間";           
else{            
if(customer[i].room.degree==2) 
cout<<"標準間";            
else{             
if(customer[i].room.degree==3)            
cout<<"豪華間";      
}     
}            
cout<<"\t房間類型:";     
if(customer[i].room.type==1)             
cout<<"單人間";           
else{            
if(customer[i].room.type==2)             
cout<<"雙人間";            
else{             
if(customer[i].room.type==3)               
cout<<"三人間";      
}        
}            
cout<<"\t樓層:"<<customer[i].room.floor;     
cout<<endl;       
cout<<"修改信息,請輸入:"<<endl;     
cout<<"輸入客人姓名:";              
cin>>customer[i].name;              
cout<<"入住時間:";              
cin>>customer[i].date;              
cout<<"入住期限:";              
cin>>customer[i].day;              
cout<<"每日租金:";               
cin>>customer[i].everydaymoney;              
cout<<"房間號:";               
cin>>customer[i].room.id;               
cout<<"房間等級(1-經濟2-標準3-豪華):";              
cin>>customer[i].room.degree;               
cout<<"房間類型(1-單人2-雙人3-三人):";              
cin>>customer[i].room.type;              
cout<<"樓層:";               
cin>>customer[i].room.floor;              
cout<<endl;    
}    
else;   
}   
if (mark== 0)    
cout<<"輸入錯誤,請從新輸入:"<<endl;   
}
while(mark == 0);
ofstream os("customer.txt",ios_base::out|ios_base::binary);  //建立、打開文件  
for(m=0;m<room.number;m++){   
os.write( reinterpret_cast<char*>(&(customer[m])),sizeof(Customer));  //導出文件  
}  
os.close();  //關閉文件 
}  
void Customer::show(){                //客人入住狀況查詢  
int i;  
for(i=0;i<room.number;i++){   
cout<<"客人姓名"<<customer[i].name;   
cout<<"\t入住時間:"<<customer[i].date;   
cout<<"\t入住期限:"<<customer[i].day;   
cout<<"\t入住押金:"<<customer[i].money;   
cout<<"\t每日租金:"<<customer[i].everydaymoney;   
cout<<"\t房間號:"<<customer[i].room.id;   
cout<<"\t房間等級:";   
if(customer[i].room.degree==1)    
cout<<"經濟間";   
else{    
if(customer[i].room.degree==2)     
cout<<"標準間";    
else{     
if(customer[i].room.degree==3)      
cout<<"豪華間";    
}   
}   
cout<<"\t房間類型:";   
if(customer[i].room.type==1)    
cout<<"單人間";   
else{    
if(customer[i].room.type==2)     
cout<<"雙人間";    
else{     
if(customer[i].room.type==3)      
cout<<"三人間";    
}   
}   
cout<<"\t樓層:"<<customer[i].room.floor;   
cout<<endl;  
} 
}  
void Customer::findByfloor(){            //顯示樓層信息  
int n;  
int mark = 0; //設置標記 
int i;   
cout<<"請輸入樓層:";  
do{   
cin>>n;   
cout<<endl;   
for(i=0;i<room.number;i++){    
if(customer[i].room.floor==n){     
mark = 1;     
cout<<"信息以下:"<<endl;     
cout<<"客人姓名:"<<customer[i].name;           
cout<<"\t入住時間:"<<customer[i].date;           
cout<<"\t入住期限:"<<customer[i].day;           
cout<<"\t入住押金:"<<customer[i].money;           
cout<<"\t每日租金:"<<customer[i].everydaymoney;           
cout<<"\t房間號:"<<customer[i].room.id;           
cout<<"\t房間等級:";     
if(customer[i].room.degree==1)cout<<"經濟間";           
else{            
if(customer[i].room.degree==2)              
cout<<"標準間";            
else{             
if(customer[i].room.degree==3)            
cout<<"豪華間";      
}     
}           
cout<<"\t房間類型:";     
if(customer[i].room.type==1)             
cout<<"單人間";           
else{            
if(customer[i].room.type==2)             
cout<<"雙人間";            
else{             
if(customer[i].room.type==3)               
cout<<"三人間";      
}        
}           
cout<<"\t樓層:"<<customer[i].room.floor;         
}    
else;   
}   
if (mark== 0)    
cout<<"輸入錯誤,請從新輸入:"<<endl; 
}
while(mark == 0); 
}  
void Customer::changemoney(){          //押金修改  
int mark = 0;   //設置標記  
int i,m;  
string x;  
cout<<"請輸入客戶名:";  
do{   
cin>>x;   
cout<<endl;   
for(i=0;i<room.number;i++){    
if(customer[i].name==x){     
mark = 1;     
cout<<"客人姓名"<<customer[i].name;           
cout<<"\t入住時間:"<<customer[i].date;           
cout<<"\t入住期限:"<<customer[i].day;           
cout<<"\t入住押金:"<<customer[i].money;           
cout<<"\t每日租金:"<<customer[i].everydaymoney;           
cout<<"\t房間號:"<<customer[i].room.id;           
cout<<"\t房間等級:";     
if(customer[i].room.degree==1)             
cout<<"經濟間";           
else{            
if(customer[i].room.degree==2)              
cout<<"標準間";            
else{             
if(customer[i].room.degree==3)            
cout<<"豪華間";      
}     
}           
cout<<"\t房間類型:";     
if(customer[i].room.type==1)             
cout<<"單人間";           
else{            
if(customer[i].room.type==2)             
cout<<"雙人間";           
else{          
if(customer[i].room.type==3)   
cout<<"三人間";    
} 
}
cout<<"\t樓層:"<<customer[i].room.floor;
cout<<"修改押金,請輸入:"<<endl;     
cin>>customer[i].money;
cout<<endl;
}
else;
}
if (mark== 0) 
cout<<"輸入錯誤,請從新輸入:"<<endl;
}
while(mark == 0);  
ofstream os("customer.txt",ios_base::out|ios_base::binary);  //建立、打開文件 
for(m=0;m<room.number;m++){ 
os.write( reinterpret_cast<char*>(&(customer[m])),sizeof(Customer) );  //導出文件  
} 
os.close();  //關閉文件 
}  
void Customer::print(){              //統計收入  
int n=0; 
for(int i=0;i<room.number;i++){ 
n+=customer[i].everydaymoney*customer[i].day;     //每日租金*入住天數  
} 
cout<<"目前爲止的收入爲:"<<n<<""<<endl;
} 
void Customer::rank(){         //客房類型入住量排序
int choose;
int m1=0,m2=0,m3=0;
int n1=0,n2=0,n3=0;
cout<<"1.按房間等級排序;"<<endl; 
cout<<"2.按房間人數排序;"<<endl; 
cout<<"輸入你的選擇:"<<endl; 
cin>>choose;
switch(choose){
case 1:
for(int i=0;i<room.number;i++){ 
if(customer[i].room.degree==1){
n1+=customer[i].room.degree;
}
if(customer[i].room.degree==2){
n2+=customer[i].room.degree;
}
if(customer[i].room.degree==3){
n3+=customer[i].room.degree;
}
} 
if((n1>n2 && n1>n3) && (n2>n3))
cout<<"1.經濟間"<<endl;
cout<<"2.標準間"<<endl;
cout<<"3.豪華間"<<endl;
if((n1>n2 && n1>n3) && (n3>n2))
cout<<"1.經濟間"<<endl;
cout<<"2.豪華間"<<endl;
cout<<"3.標準間"<<endl;
if((n3>n1 && n3>n2) && (n1>n2))
cout<<"1.豪華間"<<endl;
cout<<"2.經濟間"<<endl;
cout<<"3.標準間"<<endl;
        if((n3>n1 && n3>n2) && (n2>n1))
cout<<"1.豪華間"<<endl;
cout<<"2.標準間"<<endl;
cout<<"3.經濟間"<<endl;
if((n2>n1 && n2>n3) && (n1>n3))
cout<<"1.標準間"<<endl;
cout<<"2.經濟間"<<endl;
cout<<"3.豪華間"<<endl;
if((n2>n1 && n2>n3) && (n3>n1))
cout<<"1.標準間"<<endl;
cout<<"2.豪華間"<<endl;
cout<<"3.經濟間"<<endl;
break;
case 2:  
for(int i=0;i<room.number;i++){ 
if(customer[i].room.type==1){
m1+=customer[i].room.degree;
}
if(customer[i].room.type==2){
m2+=customer[i].room.degree;
}
if(customer[i].room.type==3){
m3+=customer[i].room.degree;
}
} 
if((m1>m2 && m1>m3) && (m2>m3))
cout<<"1.單人間"<<endl;
cout<<"2.雙人間"<<endl;
cout<<"3.三人間"<<endl;
if((m1>m2 && m1>m3) && (m3>m2))
cout<<"1.單人間"<<endl;
cout<<"2.三人間"<<endl;
cout<<"3.雙人間"<<endl;
if((m3>m1 && m3>m2) && (m1>m2))
cout<<"1.三人間"<<endl;
cout<<"2.單人間"<<endl;
cout<<"3.雙人間"<<endl;
        if((m3>m1 && m3>m2) && (m2>m1))
cout<<"1.三人間"<<endl;
cout<<"2.雙人間"<<endl;
cout<<"3.單人間"<<endl;
if((m2>m1 && m2>m3) && (m1>m3))
cout<<"1.雙人間"<<endl;
cout<<"2.單人間"<<endl;
cout<<"3.三人間"<<endl;
if((m2>m1 && m2>m3) && (m3>m1))
cout<<"1.雙人間"<<endl;
cout<<"2.三人間"<<endl;
cout<<"3.單人間"<<endl;
break;
default:
cout<<"輸入錯誤,請從新輸入!"<<endl;
}
}
void Customer::run(){
bool userExited=false;   
while(!userExited){ 
int userSelection=myMenu.MainMenu();
switch(userSelection){  
case 1:             //客人信息錄入    
input(); 
break;
case 2: //顯示樓層信息   
findByfloor(); 
break;  
case 3:             //客人入住狀況查詢  
show(); 
break; 
case 4:             //押金修改   
changemoney();  
break;  
case 5:             //修改客人信息  
alter();  
break;  
case 6:             //統計收入
print(); 
   break;  
case 7:             //客房類型入住量排序
rank();
break;
case 8:             //退出系統   
userExited=true;  
}   
if(userSelection!=8){   
cout<<"流程將返回主界面,";  
system("pause");  
}   
else   
cout<<"你選擇了退出功能,程序將結束運行!"; 
}
} 
int main(){ 
Customer myApp; 
myApp.run();
return 0;
}
相關文章
相關標籤/搜索