You are on page 1of 5

#include<iostream.

h>
#include<dos.h>
#include<fstream.h>
#include<conio.h>
#include<process.h>
#include<ctype.h>
#include<stdio.h>
#include<string.h>
fstream file1,file2;
class hotel
{
char cust_name[30];
int room_no;
int room_tariff;
char room_type[30];
public:
void add_room();
void del_room();
void mod_room();
void que_room();
void display();
}h1;
void hotel::add_room()
{
char ch;
ch='Y';
while(ch=='Y')
{
file1.open("rambo.dat",ios::app|ios::out|ios::binary);
cout<<"Enter the room no:";
cin>>h1.room_no;
cout<<"Enter the customer name:";
gets(h1.cust_name);
cout<<"Enter the room tariff:";
cin>>h1.room_tariff;
cout<<"Enter the room type(Deluxe/Standard):";
gets(h1.room_type);
file1.write((char*)&h1,sizeof(h1));
cout<<"Do you want to continue:";
cin>>ch;
ch=toupper(ch);
file1.close();
}
}
void hotel::del_room()
{
int x;
char reply;
do
{
file1.open("rambo.dat",ios::in|ios::binary);
file2.open("rocky.dat",ios::out|ios::binary);
cout<<"Enter the room no whose record is to be deleted:";
cin>>x;
while(file1.read((char*)&h1,sizeof(h1)))
{
if(h1.room_no!=x)
{
file2.write((char*)&h1,sizeof(h1));
}
}
file1.close();
file2.close();
file1.open("rambo.dat",ios::out|ios::binary);
file2.open("rocky.dat",ios::in|ios::binary);
file2.seekg(0,ios::beg);
while(file2.read((char*)&h1,sizeof(h1)))
{
file1.write((char*)&h1,sizeof(h1));
}
file1.close();
file2.close();
cout<<"Do you want to continue:";
cin>>reply;
reply=toupper(reply);
}
while(reply=='Y');
h1.display();
}
void hotel::mod_room()
{
int y ;
char reply;
do
{
cout<<"Enter the room no whose record is to be modified:";
cin>>y;
file1.open("rambo.dat",ios::in|ios::binary);
file2.open("rocky.dat",ios::out|ios::binary);
while(file1.read((char*)&h1,sizeof(h1)))
{
if(h1.room_no!=y)
{
file2.write((char*)&h1,sizeof(h1));
}
if(h1.room_no==y)
{
cout<<"Enter the new fields of the record : ";
cout<<"\n Enter the room no : ";
cin>>h1.room_no;
cout<<"Enter the nameof the customer : ";
gets(h1.cust_name);
cout<<"Enter the type of the room(Deluxe/Standard) : ";
gets(h1.room_type);
cout<<"Enter the tariff of the room : ";
cin>>h1.room_tariff;
file2.write((char*)&h1,sizeof(h1));
}
}
file1.close();
file2.close();
file1.open("rambo.dat",ios::out|ios::binary);
file2.open("rocky.dat",ios::in|ios::binary);
//file2.seekg(0,ios::beg);
while(file2.read((char*)&h1,sizeof(h1)))
{
file1.write((char*)&h1,sizeof(h1));
}
file1.close();
file2.close();
cout<<"Do you want to modify another record : ";
cin>>reply;
reply=toupper(reply);
}
while(reply=='y');
h1.display();
}
void hotel::que_room()
{
int z,reply;
do
{
cout<<"Enter the room no whose report is required : ";
cin>>z;
file1.open("rambo.dat",ios::in|ios::binary);
while(file1.read((char*)&h1,sizeof(h1)))
{
if(h1.room_no==z)
{
cout<<"\n The room no. is : "<<h1.room_no;
cout<<"\n The customer name is : "<<h1.cust_name;
cout<<"\n The room type is : "<<h1.room_type;
cout<<"\n The room tariff is : "<<h1.room_tariff;
}
}
cout<<"Do you want the report of another
room (y/n)? ";
cin>>reply;
reply=toupper(reply);
file1.close();
}
while(reply=='Y');
}
void hotel::display()
{
clrscr();
file1.open("rambo.dat",ios::in|ios::app|ios::binary);
file1.seekg(0,ios::beg);
gotoxy(4,1);
cout<<"Room No.";
gotoxy(20,1);
cout<<"Customer Name";
gotoxy(40,1);
cout<<"Type";
gotoxy(60,1);
cout<<"Tariff";

cout<<"\n================================================================
======";
int i=3;
while(file1.read((char*)&h1,sizeof(h1)))
{
cout<<endl;
gotoxy(4,i);
cout<<h1.room_no;
gotoxy(20,i);
cout<<h1.cust_name;
gotoxy(40,i);
cout<<h1.room_type;
gotoxy(60,i);
cout<<h1.room_tariff;
++i;
}
getch();
}
void main()
{
clrscr();
int reply,flag;
flag=1;
while(flag==1)
{
cout<<"\n\n\t\t\tM & M HOTEL MANAGEMENT SYSTEM ";
cout<<"\n\n\n";

cout<<"============================================================
==============";
cout<<"\n\n\t\t\t M A I N - M E N U ";
cout<<"\n\n\t\t\t1. A D D A R O O M";
cout<<"\n\n\t\t\t2. D E L E T E A R O O M";
cout<<"\n\n\t\t\t3. M O D I F Y A R O O M";
cout<<"\n\n\t\t\t4. Q U E R Y";
cout<<"\n\n\t\t\t5. D I S P L A Y";
cout<<"\n\n\t\t\t6. E X I T ";

cout<<"\n==========================================================
================";
cout<<"\n\n\n\n\n Enter your choice(1-6) : ";
cin>>reply;
switch(reply)
{
case 1:
{
h1.add_room();
break;
}
case 2:
{
h1.del_room();
break;
}
case 3:
{
h1.mod_room();
break;
}
case 4:
{
h1.que_room();
break;
}
case 5:
{
h1.display();
break;
}
case 6:
{
clrscr();
cout<<"\n\n\n\n\n\n\t\tThanks for using the
system...C U SOON..!!!!!";
getch();
exit(0);
}
default:
{
clrscr();
cout<<"Wrong choice entered......";
cout<<"\nPress any key to continue....";
getch();
}
}
}
}

You might also like