I'm currently working on a project regarding hotel management. The program has various features such as modify record, add record, search specific record, etc. however the delete record function is working BUT WHEN I USE OTHER FUNCTIONS AFTER DELETING A RECORD, SAY RECORD NUMBER 101, THAT RECORD WILL STILL BE THERE IN MY OTHER FUNCTIONS. That means that the record is not yet deleted. HELP!!! THIS IS V.V.V.URGENT!!! PLEASE SOMEONE CAN YOU TELL ME WHAT TO DO OR HOW TO FIX THE CODE THANKS!
Files are used with classes in this program.
enter code here
#include<iostream.h>
#include<fstream.h>
#include<conio.h>
#include<stdio.h>
#include<iomanip.h>
#include<dos.h>
#include<stdlib.h>
class Hotel
{
int room_no;
char name[30];
char address[50];
int age;
char nationality[30];
int choice;
public:
void main_menu();
void bookroom();
void displayrec();
void roomlist();
void editrec();
int checkstat(int);
void updaterec(int);
void deleterec(int);
void roomservice();
};
Hotel h;
void Hotel::bookroom()
{
clrscr();
int room,flagvar;
char bookchoice='y';
while (bookchoice=='y'||bookchoice=='Y')
{
ofstream f1("Hotel.dat",ios::app);
cout<<"\n--------------------------------------------";
cout<<"\n Enter details of new customer as follows: ";
cout<<"\n--------------------------------------------";
cout<<"\n\n\nRoom number: ";
cin>>room;
flagvar=checkstat(room);
if (flagvar)
cout<<"\n Sorry...Room is already booked";
else
{
room_no=room;
cout<<" Name: ";
gets(name);
cout<<"\n Address: ";
gets(address);
cout<<"\n Age: ";
cin>>age;
cout<<"\n Nationality: ";
gets(nationality);
cout<<"\n Enter 1 for single bed or any other number for double bed";
cin>>choice;
f1.write((char*)&h,sizeof(h));
cout<<"\n Room has been booked";
}
f1.close();
cout<<"\n Would you like to book another room?";
cout<<" (y for yes/ any other key for no)";
cin>>bookchoice;
}
cout<<"\n Returning to main menu. Press any key";
getche();
h.main_menu();
}
void Hotel::displayrec()
{
clrscr();
ifstream f2("Hotel.dat",ios::in);
int room,flagvar;
cout<<"\n Enter room number of customer whose record you want to display";
cin>>room;
while (f2.read((char*)&h,sizeof(h)))
{
if (room_no==room)
{
cout<<"\n------------------";
cout<<"\n Customer details:";
cout<<"\n------------------";
cout<<"\n\n\n Room no: "<<room_no;
cout<<"\n Name: ";
puts(name);
cout<<"\n Address: ";
puts(address);
cout<<"\n Age: "<<age;
cout<<"\n Nationality: ";
puts(nationality);
cout<<"\nChoice: ";
if (choice==1)
cout<<"Single Bed";
else
cout<<"Double Bed";
flagvar=1;
break;
}
}
if (flagvar==0)
cout<<"\n Room not found or room is vacant";
cout<<"\n Returning to main menu. Press any key to continue.";
getche();
f2.close();
h.main_menu();
}
void Hotel::roomlist()
{
clrscr();
ifstream fin("Hotel.dat",ios::in);
cout<<"\n------------------------------";
cout<<"\nList of booked rooms: ";
cout<<"\n------------------------------\n";
cout<<setw(9)<<" Room No."<<setw(15)<<" Name"<<setw(15)<<"Address"<<setw(4)<<"Age"<<setw(15)<<"Nationality"<<setw(7)<<"Choice";
while (fin.read((char*)&h,sizeof(h)))
{
cout<<"\n";
cout<<setw(9)<<room_no<<setw(15)<<name<<setw(15)<<address<<setw(4)<<age<<setw(15)<<nationality;
if (choice==1)
cout<<setw(7)<<"Single";
else
cout<<setw(7)<<"Double";
}
delay(20000);
cout<<"\n Returning to main menu. Press any key to continue.";
h.main_menu();
}
void Hotel::editrec()
{
clrscr();
int room,editchoice;
char again='y';
while (again=='y'||again=='Y')
{
cout<<"\n------------------";
cout<<"\nEDIT MENU: ";
cout<<"\n------------------";
cout<<"\n\n\n1. Modify customer record";
cout<<"\n2. Delete customer record";
cout<<"\n Choose from 1-2";
cin>>editchoice;
switch (editchoice)
{
case 1:
{
cout<<"\n Enter the room number";
cin>>room;
updaterec(room);
break;
}
case 2:
{
cout<<"\n Enter the room number";
cin>>room;
deleterec(room);
break;
}
default:
{
cout<<"\n Wrong choice";
cout<<"\nWould you like to try again?(y for yes/any other key for no)";
}
}
}
cout<<"\nReturning to main menu. Press any key to continue.";
getche();
h.main_menu();
}
int Hotel::checkstat(int room)
{
int flagvar=0;
ifstream fin("Hotel.dat",ios::in);
while (!fin.eof())
{
fin.read((char*)&h,sizeof(h));
if (room_no==room)
{
flagvar=1;
break;
}
}
fin.close();
return(flagvar);
}
void Hotel::updaterec(int room)
{
clrscr();
long pos,flagvar=0;
fstream file("Hotel.dat",ios::in|ios::out|ios::binary);
while (!file.eof())
{
pos=file.tellg();
file.read((char*)&h,sizeof(h));
if (room_no==room)
{
cout<<"\n Enter new details:";
cout<<"\n\n Name: ";
gets(name);
cout<<"\n Address: ";
gets(address);
cout<<"\n Age: ";
cin>>age;
cout<<"\n Nationality: ";
gets(nationality);
cout<<"\n Enter 1 for single bed or any other number for double bed";
cin>>choice;
file.seekg(pos);
file.write((char*)&h,sizeof(h));
cout<<"\n Record is modified!";
flagvar=1;
break;
}
}
if (flagvar==0)
cout<<"\n Room not found or room is vacant";
cout<<"\n Returning to main menu. Press any key to continue.";
file.close();
h.main_menu();
}
void Hotel::deleterec(int room)
{
clrscr();
int flagvar=0;
char ch;
ifstream fin("Hotel.dat",ios::in);
ofstream fout("Temp.dat",ios::out);
while (!fin.eof())
{
fin.read((char*)&h,sizeof(h));
if (room_no==room)
{
cout<<"\n Name: ";
puts(name);
cout<<"\n Address: ";
puts(address);
cout<<"\n Age: "<<age;
cout<<"\n Nationality: ";
puts(nationality);
cout<<"\n Choice: ";
if (choice==1)
cout<<"Single Bed";
else
cout<<"Double Bed";
cout<<"\n\n Do you want to delete this record(y for yes/any other key for no): ";
cin>>ch;
if (ch!='y'||ch!='Y')
fout.write((char*)&h,sizeof(h));
flagvar=1;
}
else
fout.write((char*)&h,sizeof(h));
}
fin.close();
fout.close();
if (flagvar==0)
cout<<"\n Room not found or room is vacant";
else
{
int status,stat2;
status=remove("Hotel.dat");
if (status!=0)
cout<<"\nError removing file";
else
cout<<"\nFile successfully removed";
stat2=rename("Temp.dat","Hotel.dat");
if (stat2!=0)
cout<<"\nError renaming file";
else
cout<<"\nFile successfully renamed";
}
cout<<"\n Returning to main menu. Press any key to continue.";
getche();
h.main_menu();
}
void Hotel::roomservice()
{
clrscr();
ifstream fin("Hotel.dat",ios::in);
int room,flagvar=0;
char rschoice;
cout<<"\n Enter room number that requires room service";
cin>>room;
while (!fin.eof())
{
fin.getline((char*)&h,sizeof(h));
if (room_no==room)
{
cout<<"\n 1. Clean room";
cout<<"\n 2. Bring food";
cout<<"\n 3. Wash clothes";
cout<<"\n 4. Iron clothes";
cout<<"\n 5. Other reason";
cout<<"\n\n Choose 1-5";
cin>>rschoice;
switch (rschoice)
{
case 1:
{
cout<<"\nCleaner has been sent";
break;
}
case 2:
{
cout<<"\nCrew member has been sent with menu card";
break;
}
case 3:
{
cout<<"\nSpecialised crew member has been sent";
break;
}
case 4:
{
cout<<"\nSpecialised crew member has been sent";
break;
}
case 5:
{
cout<<"\nGeneral crew member has been sent";
break;
}
default:
{
cout<<"\nWrong choice entered";
break;
}
}
flagvar=1;
}
}
if (flagvar==0)
cout<<"\n Room not found or room is vacant";
cout<<"\n Returning to main menu. Press any key to continue.";
getche();
fin.close();
h.main_menu();
}
void Hotel::main_menu()
{
clrscr();
int mainchoice;
char againchoice='y';
while (againchoice=='y'||againchoice=='Y')
{
cout<<"\n\t\t\t\tMAIN MENU";
cout<<"\n\n\t1. Book a room";
cout<<"\n\n\t2. Display specific record";
cout<<"\n\n\t3. View room list";
cout<<"\n\n\t4. Edit specific record (Modify or delete)";
cout<<"\n\n\t5. Manage room service of specific room";
cout<<"\n\n\t6. Exit";
cout<<"\n Choose from 1-6";
cin>>mainchoice;
switch (mainchoice)
{
case 1:
{
bookroom();
break;
}
case 2:
{
displayrec();
break;
}
case 3:
{
roomlist();
break;
}
case 4:
{
editrec();
break;
}
case 5:
{
roomservice();
break;
}
case 6:
{
exit(0);
}
default:
{
cout<<"\nWrong choice";
break;
}
}
cout<<"\nWould you like to try again?(y for yes/any other key for no)";
cin>>againchoice;
}
}
void main()
{
cout<<"\n\t\t\t--------------------------";
cout<<"\n\t\t\t HOTEL MANAGEMENT PROJECT";
cout<<"\n\t\t\t--------------------------";
cout<<"\n\n\nWelcome to this app designed to ease the job of administrative staff of JW Marriott";
cout<<"\n\nThis app provides various features that ease the process of managing our esteemed hotel, JW Marriott";
cout<<"\n\n\n\n\t\t\tMade by: Kartikeya Bhardwaj";
cout<<"\n\n\n\n\nPress any key to continue";
getche();
h.main_menu();
cout<<"\n\n\n Thank you for using this application!";
cout<<"\n\n The creator hopes you use it again";
cout<<"\n\n Exiting program in 12 seconds";
delay(200);
getche();
}
Aucun commentaire:
Enregistrer un commentaire