Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Code Help !! . I am having few problems in the checkout function 1. After the bill has been displayed it should return to

C++ Code Help !! . I am having few problems in the checkout function

1. After the bill has been displayed it should return to the main screen when I press on any keys but currently the bill is displayed again and again.

It will be of great help if anyone could correct my errors and send the source code.I compiled this code using code blocks Thank you in advance!!

image text in transcribed

#include #include #include #include #include #include

using namespace std;

//START OF CLASS class hotel {

int room_no; int unit; char name[30]; char address[50]; char phone[10];

public:

void additional_facilities (); //to display additional facilities void main_menu(); //to dispay the 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 void checkout(int); //for the bill of a record int check(int); //to check room status void modify(int); //to modify the record void delete_rec(int); //to delete the record

}; //END OF CLASS

//FOR DISPLAYING MAIN MENU void hotel::main_menu() {

int choice; while(choice!=7) {

system("cls"); cout>choice;

switch(choice) {

case 1: add(); break;

case 2: display(); break;

case 3: rooms(); break;

case 4: edit(); break;

case 5: additional_facilities(); break;

case 6: checkout(room_no); break;

case 7: break;

default: {

cout

}

}

}

}

//END OF MENU FUNCTION

//FUNCTION FOR BOOKING OF ROOM

void hotel::add() {

system("cls"); int r,flag; ofstream fout("Record.dat",ios::app);

cout>r;

if (r>50) cout

flag=check(r);

if(flag) cout

else {

room_no=r; cout>name; cout>address; cout>phone;

fout.write((char*)this,sizeof(hotel)); cout

} }

cout

getch(); fout.close();

}

//END OF BOOKING FUNCTION //FUNCTION FOR DISPLAYING A PARTICULAR CUSTOMER`S RECORD void hotel::display() {

system("cls");

ifstream fin("Record.dat",ios::in); int r,flag;

cout>r;

while(!fin.eof()) {

fin.read((char*)this,sizeof(hotel)); if(room_no==r) {

system("cls"); cout

}

}

if(flag==0) cout

getch(); fin.close(); }

//END OF DISPLAY FUNCTION //FUNCTION TO DISPLAY ALL ROOMS OCCUPIED void hotel::rooms() {

system("cls");

ifstream fin("Record.dat",ios::in); cout

while(!fin.eof()) {

fin.read((char*)this,sizeof(hotel)); cout

}

cout

} //FUNCTION FOR EDITING RECORDS AND FOR BILL

void hotel::edit() {

system("cls");

int choice,r; cout

cin>>choice; system("cls");

cout>r;

switch(choice) {

case 1: modify(r); break;

case 2: delete_rec(r); break;

default: cout

} cout

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);

}

//FUNCTION TO MODIFY CUSTOMERS RECORD

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>name; cout>address; cout>phone; file.seekg(pos); file.write((char*)this,sizeof(hotel)); cout

}

}

if(flag==0) cout

}

//END OF MODIFY FUNCTION //FUNCTION FOR DELETING RECORD 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>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

else {

remove("Record.dat"); rename("temp.dat","Record.dat");

}

}

//END OF DELETE FUNCTION //START OF ADDITIONAL FACILITIES void hotel::additional_facilities() { system("cls");

ifstream fin("Record.dat",ios::in); int r,flag;

cout>r;

while(!fin.eof()) {

fin.read((char*)this,sizeof(hotel)); if(room_no==r) { system("cls"); int r,flag;

cout>r;

flag=check(r);

if(r>6) cout

else {

room_no=r; unit=unit; cout>unit;

if (unit

cout

getch();

} } }

//END OF ADDITIONAL FACILITIES //FUNCTION FOR CHECKOUT void hotel::checkout(int r)

{

int room_no;

system("cls");

ifstream fin("Record.dat",ios::in);

cout

cin>>room_no;

while(!fin.eof())

{

fin.read((char*)this,sizeof(hotel));

if(room_no==r)

{

hotel h1;

ifstream f1;

f1.open("record.dat",ios::in|ios::binary);

if(!f1)

cout

else

{

f1.read((char*)&h1,sizeof (hotel));

while(f1)

{

f1.read((char*)&h1,sizeof(hotel));

}

if (h1.room_no == r)

{

if(h1.room_no>=1&&h1.room_no

cout

else if (h1.room_no>=35&&h1.room_no

cout

else {

cout

}

else

{ cout

}

f1.close();

getch();

}

}

}

//END OF CHECKOUT FUNCTION

//START OF MAIN PROGARM

int main() { hotel h;

system("cls");

cout

getch();

h.main_menu(); return 0; }

//END OF MAIN PROGRAM

Enter your room no. :- 12 your il - 2000 Name: re Address! We Pone No: 38 Do you want to delete this record(y): Y Name: re Address: we Pone Noss Do you want to delete this record y): Y our bill - 2000 Name: re Address: we Pone Not Do you want to delete this record(y) y Address: we Pone Noss Do you want to delete this recordy)! y Enter your room no. :- 12 your il - 2000 Name: re Address! We Pone No: 38 Do you want to delete this record(y): Y Name: re Address: we Pone Noss Do you want to delete this record y): Y our bill - 2000 Name: re Address: we Pone Not Do you want to delete this record(y) y Address: we Pone Noss Do you want to delete this recordy)! y

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions

Question

Describe the three major components of prejudice.

Answered: 1 week ago