Q4. (25 marks) Create a class called Hotel to represent the hotel for which the
ID: 3876187 • Letter: Q
Question
Q4. (25 marks) Create a class called Hotel to represent the hotel for which the system is created. The class has the following data members:
- Name (string)
- Address (string)
- Tel (string)
- Number of rooms (integer)
- Rooms (a collection of rooms)
The class should have at least the following member functions:
- One or more constructors
- Typical getters and setters
- Outputting the rooms with their occupation status on a given date
- Outputting the list of customers who reserved rooms in a given date interval
- Outputting the list of customers who reserved rooms of type Suite in a given date interval
- Outputting the list of customers who reserved rooms of type Regular in a given date interval
- Outputting the list of customers whose stay duration is more than or equal to an input number x
- Returning true if there are no more rooms to book (i.e., the hotel is booked up).
- A function that prints information about a hotel
- A destructor
Create a driver to test the class Hotel
in C++ please
Explanation / Answer
class hotel
{
int room_no;
string Name[30];
string Address[50];
string Tel[10];
public:
void main_menu();
void add(); //to book a room
void display(); //to display the customer record
void rooms(); //to display alloted rooms
void edit(); //to edit the customer record
int check(int); //to check room status
void modify(int); //to modify the record
void delete_rec(int); //to delete the record
};
void hotel::main_menu()
{
int choice;
while(choice!=5)
{
clrscr();
cout<<" Enter Your Choice: ";
cin>>choice;
switch(choice)
{
case 1: add();
break;
case 2: display();
break;
case 3: rooms();
break;
case 4: edit();
break;
case 5: break;
default:
{
cout<<" Wrong choice!!!";
cout<<" Press any key to continue!!";
getch();
}
}
}
}
void hotel::add()
{
clrscr();
int r,flag;
ofstream fout("Record.dat",ios::app);
cout<<" Enter Customer Detalis";
cout<<" **********************";
cout<<" Room no: ";
cin>>r;
flag=check(r);
if(flag)
cout<<" Sorry..!!!Room is already booked";
else
{
room_no=r;
cout<<" Name: ";
gets(Name);
cout<<" Address: ";
gets(Address);
cout<<" Tel No: ";
gets(Tel);
fout.write((char*)this,sizeof(hotel));
cout<<" Room is booked!!!";
}
cout<<" Press any key to continue!!";
getch();
fout.close();
}
void hotel::display()
{
clrscr();
ifstream fin("Record.dat",ios::in);
int r,flag;
cout<<" Enter room no: ";
cin>>r;
while(!fin.eof())
{
fin.read((char*)this,sizeof(hotel));
if(room_no==r)
{
clrscr();
cout<<" Cusromer Details";
cout<<" ****************";
cout<<" Room no: "<<room_no;
cout<<" Name: "<<Name;
cout<<" Address: "<<Address;
cout<<" Tel no: "<<Tel;
flag=1;
break;
}
}
if(flag==0)
cout<<" Sorry Room no. not found or vacant!!";
cout<<" Press any key to continue!!";
getch();
fin.close();
}
void hotel::rooms()
{
clrscr();
ifstream fin("Record.dat",ios::in);
cout<<" List Of Rooms Allotted";
cout<<" *********************";
cout<<" Room No. Name Address Tel No. ";
while(!fin.eof())
{
fin.read((char*)this,sizeof(hotel));
cout<<" "<<room_no<<" "<<Name;
cout<<" "<<Address<<" "<<Tel;
}
cout<<" Press any key to continue!!";
getch();
fin.close();
}
void hotel::edit()
{
clrscr();
int choice,r;
cout<<" EDIT MENU";
cout<<" *********";
cout<<" 1.Modify Customer Record";
cout<<" 2.Delete Customer Record";
cout<<" Enter your choice: ";
cin>>choice;
clrscr();
cout<<" Enter room no: ";
cin>>r;
switch(choice)
{
case 1: modify(r);
break;
case 2: delete_rec(r);
break;
default: cout<<" Wrong Choice!!";
}
cout<<" Press any key to continue!!!";
getch();
}
int hotel::check(int r)
{
int flag=0;
ifstream fin("Record.dat",ios::in);
while(!fin.eof())
{
fin.read((char*)this,sizeof(hotel));
if(room_no==r)
{
flag=1;
break;
}
}
fin.close();
return(flag);
}
void hotel::modify(int r)
{
long pos,flag=0;
fstream file("Record.dat",ios::in|ios::out|ios::binary);
while(!file.eof())
{
pos=file.tellg();
file.read((char*)this,sizeof(hotel));
if(room_no==r)
{
cout<<" Enter New Details";
cout<<" *****************";
cout<<" Name: ";
gets(Name);
cout<<" Address: ";
gets(Address);
cout<<" Tel no: ";
gets(Tel);
file.seekg(pos);
file.write((char*)this,sizeof(hotel));
cout<<" Record is modified!!";
flag=1;
break;
}
}
if(flag==0)
cout<<" Sorry Room no. not found or vacant!!";
file.close();
}
void hotel::delete_rec(int r)
{
int flag=0;
char ch;
ifstream fin("Record.dat",ios::in);
ofstream fout("temp.dat",ios::out);
while(!fin.eof())
{
fin.read((char*)this,sizeof(hotel));
if(room_no==r)
{
cout<<" Name: "<<Name;
cout<<" Address: "<<Address;
cout<<" Pone No: "<<Tel;
cout<<" Do you want to delete this record(y/n): ";
cin>>ch;
if(ch=='n')
fout.write((char*)this,sizeof(hotel));
flag=1;
}
else
fout.write((char*)this,sizeof(hotel));
}
fin.close();
fout.close();
if(flag==0)
cout<<" Sorry room no. not found or vacant!!";
else
{
remove("Record.dat");
reName("temp.dat","Record.dat");
}
}
void main()
{
hotel h;
textmode(C80);
textbackground(WHITE);
textcolor(RED);
clrscr();
cout<<" HOTEL MANAGEMENT PROJECT *";
cout<<" Press any key to continue!!";
getch();
h.main_menu();
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.