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

A small airline has just purchased a computer for its new automated reservations

ID: 3641405 • Letter: A

Question

A small airline has just purchased a computer for its new automated reservations system. You have been asked to program the new system. You are to write a program to assign seats on each flight of the airline’s only plane (capacity:10 seats).

Your program should display a menu of alternative indicating the values 1 for first class and 2 for economy. If the user types 1, your program should assign a seat in the first class section (seats 1-5). If the user types 2, your program should assign a seat in the economy section (seats 6-10). The program should display a message indicating the user’s seat number and whether it is in the first class or economy section of the plane. Your program should, of course, never assign a seat that has already been assigned. When the first class section is full, your program should ask the user if it is acceptable to be placed in the economy section (and vice versa). If yes, then make the appropriate seat assignment. If no, then display the message, "Next flight leaves in 3 hours."


(Please use Microsoft Visual Studio, C++)

Explanation / Answer

#include <iostream.h>
#include <conio.h>

int main()
{
char name[80];
int k;
int i=0,j=0;

clrscr();

cout<<" MENU"<<endl;
cout<<"enter 1 for first class"<<endl;
cout<<"enter 2 for economy class"<<endl;
cout<<"enter 3 to exit "<<endl<<endl;

do
{
cout<<"enter your name"<<endl;
cin>>name;

cout<<"enter a number from MENU"<<endl;
cin>>k;
switch(k)
{
case 1: if(i<5)
cout<<name<<"! you have been assigned no : " <<++i<<" seat in frist class"<<endl;
else if(j<5)
{
cout<<"do you want economy class? if yes press 'y' if no press 'n' "<<endl;
char ch;
cin>>ch;
if(ch=='y')
{
cout<<name<<"! you have been assigned no: " <<++j<<" seat in economy"<<endl;
break;
}
cout<<"next flight leaves in 3 hours"<<endl;
}
else
cout<<"next flight leaves in 3 hours"<<endl;
break;

case 2: if(j<5)
cout<<name<<"! you have been assigned no: " <<++j<<" seat in economy"<<endl;

else cout<<"next flight leaves in 3 hours"<<endl;
break;

case 3: cout<<name<<"! exit"<<endl;
break;

default: cout<<name<<"! enter correct number from menu"<<endl;
}
}while(k<3);
return 0;
}