Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi below is a prog. for airline registration. The user can enter as \"ADMIN\" an

ID: 3626237 • Letter: H

Question

Hi below is a prog. for airline registration. 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 the "user" should be given a randomly assigned no.(password) when he books a seat, so that he may log into his PROFILE(I DONT KNOW HOW -- maybe by using FILES( BUT NO CLASSES ), PLZ CREATE PROFILE FOR EACH "USER" WHO BOOKS A FLIGHT) which contains info about his booked seat(s). The prog. below is slightly lengthy but easy to understand.



#include <stdio.h><iostream.h><string.h><windows.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

Dear,

Here is your updated code, use visual C++ 2010 to run this program.

 

#include <stdio.h>

#include <iostream>

#include <string.h>

#include <windows.h>

#include <cstdlib>

#include <ctime>

#include <fstream>

using namespace std;

 

void main()

{

char Egypt[30][10],US[30][10],UK[30][10];

char choise='y';

int choice;

int row;

int column;

char password[25]="";

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(strcmp(password,"ADMIN")==0) //validating admin credentials

{

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 choise2='y';

while(choise2=='y')

{

       int logChoice;

       char username[25],uName[25];

       int password,pw;

cout<<" "WELCOME TO PIA HELP LINE SIR" "<<endl;

//prompts user for login or registration

cout<<"1.login 2.register 3.cancel"<<endl;

cin>>logChoice;

//filestream

ifstream inFile; //to read or write into the file

ofstream outFile;

bool flag=false;

switch(logChoice)

{

case 1:

       cout<<" username: ";

       cin>>username;

       cout<<"Password: ";

       cin>>password;      

       //opens file read mode

       inFile.open("profile.txt",ios::in);

       //searching in file for given username and password

       while(!inFile.eof())

       {

              inFile>>uName>>pw;

              if(strcmp(uName,username)==0)

                     if(password==pw)

                           flag=true;

       }

       if(!flag)

              cout<<"Invalid credentials"<<endl;

       //closes the file

       inFile.close();

       break;

case 2:

       //opens file in read mode

       inFile.open("profile.txt",ios::in);

       do

       {

              flag=false;

       cout<<"Enter desired username: ";

       cin>>username;

       //this will checks the wether the username is already existed or not

       while(!inFile.eof())

       {

              inFile>>uName>>pw;

              if(strcmp(uName,username)==0)

              {

                     cout<<"this name is already existed ";

                     cout<<"try with another name"<<endl;

                     flag=true;

                     break;

              }

       }

       //clears the ios bit of filestream

       inFile.clear();

       //seeks the cursor position to starting position in the file

       inFile.seekg(0,ios::beg);

       }while(flag);

       //closes the file

       inFile.close();

       //opens same file in append mode to insert new profile

       outFile.open("profile.txt",ios::app);

       //to generate random number as password between 1000 and 9999

       srand(time(0));

       password=(rand()+1000)%9999+1;

       cout<<" Your password: "<<password<<endl<<endl;

       //stores the new profile into the file

       outFile<<username<<" "<<password<<endl;

       //closes the file

       outFile.close();

       break;

case 3:choise2='n';

       break;

default:cout<<"Invalid choice"<<endl;

}

 

if(flag)

{

       int choiceNum;

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

cout<<endl;

int m;

switch(choiceNum)

{

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>>choise2;}}}

cout<<"Do you want to repeat this program press Y or N ";

cin>>choise;}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote