Académique Documents
Professionnel Documents
Culture Documents
#include<iostream.h>
#include<conio.h>
#include<fstream.h>
#include<stdio.h>
#include<dos.h>
class hotel
int room_no;
char name[30];
char address[50];
char phone[10];
public:
};
C++ Hotel Management Project
void hotel::main_menu()
int choice;
while(choice!=5)
clrscr();
cout<<"\n\t\t\t\t*************";
cout<<"\n\t\t\t\t*************";
cout<<"\n\n\n\t\t\t1.Book A Room";
cout<<"\n\t\t\t2.Customer Record";
cout<<"\n\t\t\t3.Rooms Allotted";
cout<<"\n\t\t\t4.Edit Record";
cout<<"\n\t\t\t5.Exit";
cin>>choice;
switch(choice)
case 1: add();
break;
case 2: display();
break;
C++ Hotel Management Project
case 3: rooms();
break;
case 4: edit();
break;
case 5: break;
default:
cout<<"\n\n\t\t\tWrong choice!!!";
getch();
void hotel::add()
clrscr();
int r,flag;
ofstream fout("Record.dat",ios::app);
cout<<"\n **********************";
cin>>r;
flag=check(r);
if(flag)
else
room_no=r;
gets(name);
gets(address);
gets(phone);
fout.write((char*)this,sizeof(hotel));
getch();
fout.close();
void hotel::display()
C++ Hotel Management Project
clrscr();
ifstream fin("Record.dat",ios::in);
int r,flag;
cin>>r;
while(!fin.eof())
fin.read((char*)this,sizeof(hotel));
if(room_no==r)
clrscr();
cout<<"\n ****************";
flag=1;
break;
}
C++ Hotel Management Project
if(flag==0)
getch();
fin.close();
void hotel::rooms()
clrscr();
ifstream fin("Record.dat",ios::in);
cout<<"\n\t\t\t*********************";
while(!fin.eof())
fin.read((char*)this,sizeof(hotel));
cout<<"\n\n "<<room_no<<"\t\t"<<name;
cout<<"\t\t"<<address<<"\t\t"<<phone;
getch();
fin.close();
void hotel::edit()
clrscr();
int choice,r;
cout<<"\n *********";
cin>>choice;
clrscr();
cin>>r;
switch(choice)
case 1: modify(r);
C++ Hotel Management Project
break;
case 2: delete_rec(r);
break;
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;
}
C++ Hotel Management Project
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<<"\n *****************";
gets(name);
gets(address);
gets(phone);
C++ Hotel Management Project
file.seekg(pos);
file.write((char*)this,sizeof(hotel));
flag=1;
break;
if(flag==0)
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));
C++ Hotel Management Project
if(room_no==r)
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)
else
{
C++ Hotel Management Project
remove("Record.dat");
rename("temp.dat","Record.dat");
void main()
hotel h;
textmode(C80);
textbackground(WHITE);
textcolor(RED);
clrscr();
cout<<"\n\t\t\t****************************";
cout<<"\n\t\t\t****************************";
sleep(2);
cout<<"\n\n\n\n\t\tMade By:";
sleep(2);
sleep(2);
getch();
C++ Hotel Management Project
h.main_menu();
Output