Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

where is the errors? #include #include #include #include using namespace std; //Global variables const int size=100; // Number of rooms (size of room array) int

where is the errors?
#include
#include
#include
#include
using namespace std;
//Global variables
const int size=100; // Number of rooms (size of room array)
int count=0;
//Structures Declaration
struct date{
int day;
int month;
int year;
};
struct reserv_info{
string name;
string pho_num;
int no_room; // room number
int no_resroom; // number of rooms
char roomtyp;
date checkin;
date checkout;
int no_days;
} room[size];
//Functions Prototypes
void readData(reserv_info arr[]);
// void writeData(reserv_info arr[], int count);
int menu();
void add_reserv(reserv_info a[],int &count);
void delete_reserv(reserv_info arr[] ,int &count);
void update_reserv(int count);
void sort_reserv(int count);
bool emptyArray (int count);
int search(int count); //search by phone number.
void show_reserv(int i);
void print_reserv(int count);
void app_reserv(reserv_info arr[], int count);
// void copyfile(reserv_info arr[], int count);
//Functions Definition:
void readData(reserv_info room[]){
string line;
ifstream iFile("hotel.txt",ios::in);
ofstream oFile("hotel.txt",ios::app);
if(oFile.is_open() && iFile.is_open()){
oFile<<"Data of the Guste: "<
while(!iFile.eof()){
iFile >> room[count].name;
iFile >> room[count].pho_num;
iFile >> room[count].no_room;
iFile >> room[count].no_resroom;
iFile >> room[count].roomtyp;
iFile >> room[count].checkin.day;
iFile >> room[count].checkin.month;
iFile >> room[count].checkin.year;
iFile >> room[count].checkout.day;
iFile >> room[count].checkout.month;
iFile >> room[count].checkout.year;
iFile >> room[count].no_days;
count++;
for(int i=0;count
oFile<<"Guste "<
oFile << room[count].name<<"\t";
oFile << room[count].pho_num<<"\t";
oFile << room[count].no_resroom<<"\t";
oFile << room[count].roomtyp<<"\t(";
oFile << room[count].checkin.day<<"/";
oFile << room[count].checkin.month<<"/";
oFile << room[count].checkin.year<<")\t(";
oFile << room[count].checkout.day<<"/";
oFile << room[count].checkout.month<<"/";
oFile << room[count].checkin.year<<")\t";
oFile << room[count].no_days<<" "<<"__________________ ";
oFile<
}
getline(iFile,line); // read from original file
oFile<< line << endl; // write to backup file
oFile.close();iFile.close();}
}
else
cout<<"The File didn't open!. ";
}
//void writeData(reserv_info a[], int count){
// ofstream oFile("hotel.txt",ios::app);
// if(oFile.is_open()==true){
// oFile<<"Data of the Guste: "<
// while(!oFile.eof()){
// for(int i=0;i
// oFile<<"Guste "<
// oFile << a[i].name<<"\t";
// oFile << a[i].pho_num<<"\t";
// oFile << a[i].no_resroom<<"\t";
// oFile << a[i].roomtyp<<"\t(";
// oFile << a[i].checkin.day<<"/";
// oFile << a[i].checkin.month<<"/";
// oFile << a[i].checkin.year<<")\t(";
// oFile << a[i].checkout.day<<"/";
// oFile << a[i].checkout.month<<"/";
// oFile << a[i].checkin.year<<")\t";
// oFile << a[i].no_days<<" "<<"__________________ ";
// oFile<
// }
// oFile.close();}
// }
//
//cout<<"The File didn't open!. ";
//}
//void copyfile(reserv_info a[], int count){
// ofstream oFile("read_hotel.txt",ios::out);
// ifstream iFile("write_hotel.txt",ios::in);
// if(oFile.is_open()==true && iFile.is_open()==true){
// for(int i=0;i
// while (!iFile.eof()){
// getline(iFile,a[i].name);
// oFile<
// getline(iFile,a[i].pho_num);
// oFile<
//
// }oFile.close();iFile.close();
// }
// }else{cout<<"The File didn't open!. ";}
//}
int menu()
{
int choice;
cout<<" Please choose a task:"
<<" 1 - Add a new reservation"
<<" 2 - Delete a Guste"
<<" 3 - Update a Guste"
<<" 4 - View all reservation of Guste"
<<" 5 - Find Guste by phone number"
<<" 6 - sort Guste by date of check in"
<<" 7 - Exit"
<<" ***********************************"
<<" >> ";
cin>>choice;
return choice;
}//end of menu
void add_reserv(reserv_info g[], int &count){
cout<<"Please Enter Guste Information: ";
cout<<" Guste Name: "; cin.ignore(); getline(cin, room[count].name);
cout<<" Phone Number: ";cin>>g[count].pho_num;
cout<<" Number Of Rooms To Reserve: "; cin>>g[count].no_resroom;
cout<<" Guest Room Type (M for master/ R for Regular ): "; cin>>g[count].roomtyp;
cout<<" Date of Checkin (DD-MM-YYYY): ";
cout<<" Day (1-31): "; cin>>g[count].checkin.day;
cout<<"Month (1-12): "; cin>>g[count].checkin.month;
cout<<"Year: " ; cin>>g[count].checkin.year;
cout<<" Date of Checkout (DD-MM-YYYY): ";
cout<<" Day (1-31): "; cin>>g[count].checkout.day;
cout<<"Month (1-12): "; cin>>g[count].checkout.month;
cout<<"Year: " ; cin>>g[count].checkout.year;
cout<<" Number Of Reserved Days: "; cin>>g[count].no_days;
count++;
} //end of add_record
void show_reserv(int i){
cout<< (i+1) << " Guest name: " << room[i].name<< " Phone number: "
<< room[i].pho_num<< " Room number: "<
<< " Number of reserve room: " <
<< room[i].roomtyp <<" Number of days: "<
<< " Date of check in (DD-MM-YYYY): "<< room[i].checkin.day<<"/"<< room[i].checkin.month<<"/"<< room[i].checkin.year
<<" Date of chech out (DD-MM-YYYY): "<< room[i].checkout.day<<"/"<
// << " Reservation cost: " << room[i].cost
cout<< " _________________________________________________";
}
void print_reserv(int count){
// print all reservations //
for(int i=0; i
show_reserv(i);
} // end of the print record//
bool emptyArray(int count)
{
if (count==0)
{
cout<<" ERROR: Rooms is empty!! ";
return true;
}//end if
return false;
}//end of empty Array
int search(int count){
//classic search by phone number
string phone;
cout<<" Please enter a Guest Phone Number:";
cin>>phone;
for (int i=0;i
if (room[i].pho_num==phone)
return i;
return -1; //i.e. not found
}//end of search by Phone Number.
void sort_reserv(int count){
// sort chick in by increase
bool order = false;
reserv_info temp;
if (count < 2)
cout<<"Nothing to sort";
for(int i=0; i
order=true;
for ( int j=0; j
if(room[j].checkin.day>= room[j+1].checkin.day && room[j].checkin.month>= room[j+1].checkin.month && room[j].checkin.year>= room[j+1].checkin.year)
order=false;
temp= room[j];
room[j]=room[j+1];
room[j+1] = temp; }
//end the first for loop
cout<< " Check in sorted from the nearest reservation "; } }
void delete_reserv(reserv_info arr[] ,int &count){
int index=search(count);
if (index<0)
{
cout<<" Not found!! ";
return; //exit from the function
}//end if
//delete if found index>=0
for (int j=index; j< count; j++)
room[j]=room[j+1];
count--;
cout<<" The Guest deleted successfully. ";
}//end of delete_reserv.
void update_reserv(int count){
// update number of days only //
int index=search(count);
if (index<0)
{
cout<<" Not found!! ";
return; //exit from the function
}//end if
// ubdate if found index > 0 //
cout<< " old number of days : "<< room[index].no_days;
cout<< "new number of days : ";
cin>>room[index].no_days;
// room[index].cost=price(room[index].roomtyp, room[index].no_resroom, room[index].no_days); //calculate new coast//
cout<<"number of rooms updated successfully";
// end of update reservation //
}
int main (){
// copyfile(room, count);
int choice;
cout<<" <________________.Welcom to our hotel sestm.________________> ";
//show a menu to the user
do{
choice=menu();
switch (choice){
case 1: //Add new reservation
if (count
add_reserv(room,count);
cout<<"Added successfully";}
else{
cout<<" ERROR: The rooms is full.You need to delete items first!";}
break;
case 2: // delete reservation //
if(!emptyArray(count))
delete_reserv(room, count);
cout<<"item deteted successfully";
break;
case 3: // update number of days//
if(!emptyArray(count))
update_reserv(count);
cout<<"item updeted successfully";
break;
case 4: // print all reservations //
if(!emptyArray(count))
print_reserv(count);
cout<<" ";
break;
case 5: // Find a guste by phone number//
if (!emptyArray(count))
{ int i=search(count);
if (i>=0)
show_reserv(i);
else
cout<<" Not found!! ";
}//end
break;
case 6: // sort reservation //
if (!emptyArray(count))
sort_reserv(count);
break;
case 7: // exit from the menu//
cout<< "***You exit the system***"<
break;
default: cout<< " incorrect menu option ";}
}while(choice!=7);
readData(room);
// writeData( room,count);
return 0;} //end of main function.

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

Recommended Textbook for

Transactions On Large Scale Data And Knowledge Centered Systems Xxviii Special Issue On Database And Expert Systems Applications Lncs 9940

Authors: Abdelkader Hameurlain ,Josef Kung ,Roland Wagner ,Qimin Chen

1st Edition

3662534541, 978-3662534540

More Books

Students also viewed these Databases questions

Question

Describe how gas chromatography works.

Answered: 1 week ago

Question

Is conflict always unhealthy? Why or why not? (Objective 4)

Answered: 1 week ago