#include<iostream.h>
#include<string.h>
#include<stdlib.h>
#include<fstream.h>
#include<iomanip.h>
int i;
int Tel_temp;
void change_R(int num);
void change_D(int num);
void change_RR(int num);
/***************定义旅馆详细信息类***********************/
class Hotel
{
private:
int Hotel_code; //代码(从1开始按顺序编码)
char Hotel_name[30]; //名字(最多30个字符)
char Hotel_City_name[30]; //城市的名字(最多30个字符)
int Regular_total; //标准间的总数
float Regular_tariff; //标准间的价格表
int Regular_num; //可预订标准间的数目
int Deluxe_total; //豪华间的总数
float Deluxe_tariff; //豪华间的价格表
int Deluxe_num; //可预订豪华间的数目
public:
void getHotel(); //接收输入的信息
void showHotel(); //显示对象中的各项信息
int get_Hotel_code();
int get_Regular_num();
int get_Deluxe_num();
friend void change_R(int num);
friend void change_D(int num);
char *get_Hotel_City_name(void);
void return_Add_R();
void return_Add_D();
};
void Hotel::getHotel()
{
system("cls");
Hotel_code=i; //获取全局变量i赋值于Hotel_code
cout<<Hotel_code;
cin>>Hotel_name;
cin>>Hotel_City_name;
cin>>Regular_total;
Regular_num=Regular_total;
cin>>Regular_tariff;
cin>>Deluxe_total;
Deluxe_num=Deluxe_total;
cin>>Deluxe_tariff;
}
void Hotel::showHotel()
{
cout<< cout<<"Hotel code:"<< cout<<"\t"<<"Name:"<< cout<<"Regular rooms:"<< cout<<"\t"<<"Tariff:"<< Regular_tariff;
cout<<"\t"<<"Available:"<< cout<<"Deluxe rooms:"<< cout<<Regular_num<<"\t"<<"Tariff:"<< Deluxe_tariff;
cout<<"\t"<<"Available:"<<Deluxe_num;
}
int Hotel::get_Hotel_code()
{
return Hotel_code;
}
int Hotel::get_Regular_num()
{
return Regular_num;
}
int Hotel::get_Deluxe_num()
{
return Deluxe_num;
}
char* Hotel::get_Hotel_City_name(void)
{
return Hotel_City_name;
}
void Hotel::return_Add_R()
{
Regular_num+=1;
}
void Hotel::return_Add_D()
{
Deluxe_num+=1;
}
/*****************定义度假村详细信息类*********************/
class Resort
{
private:
int Resort_code; //代码(从1开始按顺序编码)
char Resort_name[30]; //名字(最多30个字符)
char Resort_city_name[30]; //城市的名字(最多30个字符)
int Cottages_total; //小别墅的总数
float Cottages_tariff; //小别墅的价格表
int Cottages_num; //可预订的小别墅数目
public:
void getResort(); //接收输入的信息
int get_Resort_code();
int get_Cottages_num();
char* get_Resort_City_name(void);
void showResort();
friend void change_RR(int num);
void return_Add_RR();
};
void Resort::return_Add_RR()
{
Cottages_num+=1;
}
void Resort::getResort()
{
system("cls");
Resort_code=i;
cout<< Resort_code;
cin>>Resort_name;
cin>>Resort_city_name;
cin>>Cottages_total;
Cottages_num=Cottages_total;
cin>>Cottages_tariff;
}
int Resort::get_Resort_code()
{
return Resort_code;
}
int Resort::get_Cottages_num()
{
return Cottages_num;
}
char* Resort::get_Resort_City_name(void)
{
return Resort_city_name;
}
void Resort::showResort()
{
Cottages_num=Cottages_total;
cout<<"\t"<<"Name:"<< cout<<"Total cottages:"<< cout<<"\t"<<"Tariff:"<< Cottages_num;
cout<<"\t"<<"Available:"<<Cottages_num;
}
/*****************定义预订的详细信息类**********************/
class Booking:public Hotel,public Resort
{
private:
int Booking_code; //预订编号(从1开始按顺序编码)
int H_code;
char Name[30]; //顾客的名字(最多30个字符)
int Tel; //联系电话
char Email[30]; //电子邮件 ID(最多30个字符)
char H_R;
char R_D;
public:
void getBooking();
int get_H_code();
int get_Booking_code();
int get_Booking_H_R();
int get_Booking_R_D();
};
int Booking::get_H_code()
{
return H_code;
}
int Booking::get_Booking_code()
{
return Booking_code;
}
int Booking::get_Booking_H_R()
{
return H_R;
}
int Booking::get_Booking_R_D()
{
return R_D;
}
void Booking::getBooking()
{
system("cls");
cout<<"Booking for Hotel or Resort?(H/R):";
cin>>H_R;
if(H_R=='H' || H_R=='h')
{
int x,temp_x=0;
cout<<"Enter Hotel code:";
cin>>x;
Hotel Booking_Hotel;
fstream file_H;
file_H.open("Hotel.dat",ios::in);
file_H.read((char *)&Booking_Hotel,sizeof(Booking_Hotel));
while(!file_H.eof())
{
file_H.read((char *)&Booking_Hotel,sizeof(Booking_Hotel));
temp_x++;
}
file_H.close();
if(x>temp_x)
{
cout<<"INUALID HOTEL CODE! Plase re-enter.";
}
else
{
int R_num=0;
int D_num=0;
do
{
cout<<"Enter required room type('R' for regular,'D' for Deluxe):";
cin>>R_D;
if(R_D!='R' && R_D!='r' && R_D!='D' && R_D!='d')
{
cout<<"PLEASE ENTER 'R' OR 'r' FOR REGULAR OR 'D' OR 'd' FOR DELUXE."<<"\n";
}
}while(R_D!='R' && R_D!='r' && R_D!='D' && R_D!='d' && R_D!='R' && R_D!='r' && R_D!='D' && R_D!='d');
if(R_D=='R' || R_D=='r')
{
char ch='n';
do
{
Hotel H_a;
int ta;
fstream file_H_a;
file_H_a.open("Hotel.dat",ios::in);
file_H_a.read((char *)&H_a,sizeof(H_a));
while(!file_H_a.eof())
{
ta=H_a.get_Hotel_code();
if(x==ta)
{
R_num=H_a.get_Regular_num();
break;
}
file_H_a.read((char *)&H_a,sizeof(H_a));
}
file_H_a.close();
if(R_num>0)
{
Booking_code=i;
cout<<"Booking Code:"<< Booking_code;
cout<<"Enter name:";
cin>>Name;
do
{
cout<<"Enter contact number:";
cin>>Tel_temp;
if(Tel_temp<<0)
{
cout<<"Contact number cannot be less than or equal to 0."<<"\n";
}
else
{
Tel=Tel_temp;
}
}while(Tel_temp<<0);
cout<<"Enter Email ID:";
cin>>Email;
H_code=x;
change_R(x);
}
else
{
cout<<"The quantity of standard room is 0,Please reselect."<<"\n";
ch='y';
}
}while(R_num<=0 && ch!='y');
}
/*********************************************/
if(R_D=='D' || R_D=='d')
{
char ch='n';
do
{
Hotel H_b;
int tb;
fstream file_H_b;
file_H_b.open("Hotel.dat",ios::in);
file_H_b.read((char *)&H_b,sizeof(H_b));
while(!file_H_b.eof())
{
tb=H_b.get_Hotel_code();
if(x==tb)
{
D_num=H_b.get_Deluxe_num();
break;
}
file_H_b.read((char *)&H_b,sizeof(H_b));
}
file_H_b.close();
if(D_num>0)
{
Booking_code=i;
cout<<"Booking Code:"<<Booking_code;
cout<<"Enter name:";
cin>>Name;
do
{
cout<<"Enter contact number:";
cin>>Tel_temp;
if(Tel_temp<<0)
{
cout<<"Contact number cannot be less than or equal to 0.";
}
else
{
Tel=Tel_temp;
}
}while(Tel_temp<<0);
cout<<"Enter Email ID:";
cin>>Email;
H_code=x;
change_D(x);
}
else
{
cout<<"The quantity of standard room is 0,Please reselect."<<"\n";
ch='y';
}
}while(D_num<<=0 && ch!='y');
}
}
}
/*************************************/
if(H_R=='R' || H_R=='r')
{
int y,temp_y=0,tr,RR_num;
cout<<"Enter Resort code:";
cin>>y;
Resort Booking_Resort;
fstream file_R;
file_R.open("Resort.dat",ios::in);
file_R.read((char *)&Booking_Resort,sizeof(Booking_Resort));
while(!file_R.eof())