Hi below is a prog. for airline reservation. The user can enter as \"ADMIN\" and
ID: 3626393 • Letter: H
Question
Hi below is a prog. for airline reservation. The user can enter as "ADMIN" and see all seats/booked seats/,empty seats and can also cancel a booked seat. The user can also enter as "USER" and can view all seats, and can book a seat. My prog. works for 3 destinations. I want that when a particular "User" books a seat, A simple Profile of him would be created using files, he may log in into his PROFILE later on to see his booked seat and destination (Do NOT USE CLASSES And Bool Flag commands! ), PLZ CREATE PROFILE FOR EACH "USER" WHO BOOKS A FLIGHT). The prog. below is slightly lengthy but very easy to understand.Could you please add to my program(it works) to accomplish what i want. THANKS A LOT!IM A NEWBIE TO FILES SO PLZ DO NOT MAKE IT DIFFICULT!
#include<windows.h>
#include<string.h>
#include<iostream.h>
#include <stdio.h>
void main()
{
char Egypt[30][10],US[30][10],UK[30][10];
char choise='y';
int choice;
int row;
int column;
int password;
int destinationChoice;
char name[10];
int role;
for(int i=0;i<30;i++) //Initializing all seats to EMPTY
{
for(int j=0;j<10;j++)
{Egypt[i][j]='E';
US[i][j]='E';
UK[i][j]='E';}
}
while(choise=='y')
{
cout<<"Press 1 for ADMIN's menu or 2 for USER's menu ";
cin>>role;
cout<<endl;
{
if(role==1)
{
{while(choise=='y')
{
cout<<" "WELCOME TO ADMIN'S MENU "<<endl;
for(int u=0;u<1;u++)
{
cout<<"Please enter the PASSWORD"<<endl;
cin>>password;
if(password==10)
{
cout<<" 1 to see all the seats "<<endl;
cout<<" 2 for seeing already BOOKED seats "<<endl;
cout<<" 3 for seeing EMPTY seats "<<endl;
cout<<" 4 for cancelling a BOOKED seat "<<endl;
}
else
{
cout<<"YOU HAVE ENTERED AN INVALID PASSWORD"<<endl<<endl;
break;
}
cin>>choice;
cout<<endl;
switch(choice)
{case 1:
{
do
{
cout<<"Enter destination 1 to Egypt 2 to US 3 to UK 4 to back menu"<<endl<<endl;
cin>>destinationChoice;
switch(destinationChoice)
{
case 1:
for(int m=0;m<30;m++)
{
for(int n=0; n<10; n++)
{cout<<m+1<<":"<<n+1<<" "<<Egypt[m][n]<<" ";}
cout<<endl;}
break;
case 2:
for(int m=0;m<30;m++)
{
for(int n=0; n<10; n++)
{cout<<m+1<<":"<<n+1<<" "<<US[m][n]<<" ";}
cout<<endl;}
break;
case 3:
for(int m=0;m<30;m++)
{
for(int n=0; n<10; n++)
{cout<<m+1<<":"<<n+1<<" "<<UK[m][n]<<" ";}
cout<<endl;}
}}while(destinationChoice<4 && (destinationChoice>0));}
break;
case 2:
{ do
{
cout<<"Enter destination 1 to Egypt 2 to US 3 to UK 4 to back menu"<<endl<<endl;
cin>>destinationChoice;
switch(destinationChoice)
{
case 1:
for(int o=0; o<30;o++)
{
for(int p=0;p<10;p++)
{
if(Egypt[o][p]=='B')
{cout<<o+1<<":"<<p+1<<Egypt[o][p]<<" ";}
}
cout<<endl;}
break;
case 2:
for(int o=0; o<30;o++)
{
for(int p=0;p<10;p++)
{
if(US[o][p]=='B')
{cout<<o+1<<":"<<p+1<<US[o][p]<<" ";}
}
cout<<endl;}
break;
case 3:
for(int o=0; o<30;o++)
{
for(int p=0;p<10;p++)
{
if(UK[o][p]=='B')
{cout<<o+1<<":"<<p+1<<UK[o][p]<<" ";}
}
cout<<endl;}break;
}}while(destinationChoice<4 && destinationChoice>0);}
break;
case 3:
do
{
cout<<"Enter destination 1 to Egypt 2 to US 3 to UK 4 to back menu"<<endl<<endl;
cin>>destinationChoice;
switch(destinationChoice)
{
case 1:
{for(int q=0;q<30;q++)
for(int l=0;l<10;l++)
{if(Egypt[q][l]=='E')
{cout<<q+1<<":"<<l+1<<Egypt[q][l]<<" ";}}
cout<<endl;}
break;
case 2:
{for(int q=0;q<30;q++)
for(int l=0;l<10;l++)
{if(US[q][l]=='E')
{cout<<q+1<<":"<<l+1<<US[q][l]<<" ";}}
cout<<endl;}
break;
case 3:
{for(int q=0;q<30;q++)
for(int l=0;l<10;l++)
{if(UK[q][l]=='E')
{cout<<q+1<<":"<<l+1<<UK[q][l]<<" ";}}
cout<<endl;}
}
}while(destinationChoice<4 &&destinationChoice>0);
break;
case 4:
cout<<"Enter destination 1 to Egypt 2 to US 3 to UK "<<endl<<endl;
cin>>destinationChoice;
cout<<"Please enter the row of seat ";
cin>>row;
row=row-1;
cout<<"Please enter the column of seat ";
cin>>column;
column=column-1;
switch(destinationChoice)
{
case 1:
if(Egypt[row][column]=='B')
{Egypt[row][column]='E';
cout<<"The reserved seat is changed to EMPTY"<<endl;}
else
{cout<<"The given seat is already EMPTY"<<endl;}
break;
case 2:
if(US[row][column]=='B')
{US[row][column]='E';
cout<<"The reserved seat is changed to EMPTY"<<endl;}
else
{cout<<"The given seat is already EMPTY"<<endl;}
break;
case 3:
if(UK[row][column]=='B')
{UK[row][column]='E';
cout<<"The reserved seat is changed to EMPTY"<<endl;}
else
{cout<<"The given seat is already EMPTY"<<endl;}
break;}
}
cout<<"Do you want to repeat the menu press Y or N ";
cin>>choise;}}}}
if(role==2)
{
char choise='y';
while(choise=='y')
{
cout<<" "WELCOME TO PIA HELP LINE SIR" "<<endl;
cout<<"Please enter the name of the country for which you want to fly (Egypt,US,UK) "<<endl;
cin>>name;
cout<<" Now press 6 for viewing all the seats in that flight "<<endl;
cout<<" Now press 7 for BOOKING a seat in that flight "<<endl;
cin>>choice;
cout<<endl;
int m;
switch(choice)
{
case 6:
{if(strcmp(name,"Egypt")==0)
{
for(m=0;m<30;m++)
{
for(int n=0; n<10; n++)
{
cout<<m+1<<":"<<n+1<<Egypt[m][n]<<" ";}
cout<<endl;}}
else if(strcmp(name,"US")==0)
{
for(m=0;m<30;m++)
{
for(int n=0; n<10; n++)
{
cout<<m+1<<":"<<n+1<<US[m][n]<<" ";}
cout<<endl;}}
else if(strcmp(name,"UK")==0)
{
for(m=0;m<30;m++)
{
for(int n=0; n<10; n++)
{
cout<<m+1<<":"<<n+1<<UK[m][n]<<" ";}
cout<<endl;}}
else
cout<<"Invalid destination"<<endl;}
break;
case 7:
{cout<<"PLease enter row number ";
cin>>row;
row=row-1;
cout<<"Please enter he column number ";
cin>>column;
column=column-1;
cout<<endl;
if(strcmp(name,"Egypt")==0)
{
if(Egypt[row][column]=='B')
{cout<<"Sorry the seat is already BOOKED"<<endl;
Beep(20000,5000);
}
else
{Egypt[row][column]='B';
cout<<"Your seat is BOOKED enjoy the flight"<<endl;}
}
else if(strcmp(name,"US")==0)
{
if(US[row][column]=='B')
{cout<<"Sorry the seat is already BOOKED"<<endl;
Beep(20000,5000);
}
else
{US[row][column]='B';
cout<<"Your seat is BOOKED enjoy the flight"<<endl;}
}
else if(strcmp(name,"UK")==0)
{
if(UK[row][column]=='B')
{cout<<"Sorry the seat is already BOOKED"<<endl;
Beep(20000,5000);
}
else
{UK[row][column]='B';
cout<<"Your seat is BOOKED enjoy the flight"<<endl;}
}
else
cout<<"Invalid destination"<<endl;
break;
}}
cout<<"Do you want to repeat the menu press Y or N ";
cin>>choise;}}
cout<<"Do you want to repeat this program press Y or N ";
cin>>choise;}
}
}
Explanation / Answer
This doesn't work 100% because I am at work and trying to play with this in my down time. This is your code but with a couple of changes. It initially initializes all seats to E like you were doing; however, now it will read a text file called "Schedule.txt" and fill in "B" for already booked seats. Later on when a user books a seat, it will write to this file with their info. Currently it is overwriting all existing entries which is a problem but checking out the msdn on ofstream can likely provide you a solution. You will have to create the empty text file yourself. I assume you're using Visual Studio so when you have the project open, the solution explorer on the right should have a folder called "References." Right click, click add new item. In the box select the .txt file type and name it "Schedule". You can fill in any data here you want for previously booked flights. They should be in the format of "Name Destination RowXColumn" - i.e. "Mr.Owl Egypt 01x04" #include #include #include #include #include using namespace std; void main() { char Egypt[30][10],US[30][10],UK[30][10]; char menuToggle = 'y'; int choice; int row; int column; int password; int destinationChoice; char name[10]; int role; string fileLine; string newLine; string userName; string flight; ifstream bookedSeats; ofstream writeSeats; bookedSeats.open("Schedule.txt"); for(int i=0;iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.