118k views
3 votes
Create a class called Plane, to implement the functionality of the Airline Reservation System. Write an application that uses the Plane class and test its functionality. Write a method called CheckIn() as part of the Plane class to handle the check in process Prompts the user to enter 1 to select First Class Seat (Choice: 1) Prompts the user to enter 2 to select Economy Seat (Choice: 2)

User Alsin
by
3.3k points

1 Answer

1 vote

Answer:

See explaination

Step-by-step explanation:

#include <iostream>

using namespace std;

class Plane

{

private:

int firstClass;

int economy;

public:

//Constructor

Plane()

{

firstClass=0;

economy=0;

}

//reserves one seat in first class

void resrFirsClass()

{

firstClass++;

}

//reserves one seat in Economy class

void resrEconomy()

{

economy++;

}

//returns number of first class seats resreved

int getFirstClass()

{

return firstClass;

}

//returns number of economy seats reserved

int getEconomy()

{

return economy;

}

//Makes Checkin process

void CheckIn()

{

int choice;

cout<<"Enter 1 to select First Class Seat "<<endl;

cout<<"Enter 2 to select Economy Seat "<<endl;

cout<<"Choice: ";

cin>>choice;

switch(choice)

{

case 1: //check the availability in first class

if(getFirstClass()<5)

{

cout<<"Available seats in First Class: "<<5-getFirstClass()<<endl;

resrFirsClass();

cout<<"You have successfully reserved the First class seat: "<<getFirstClass()<<endl;

}

else

{

//Display that no more seats, if all first class seats are filled

cout<<"**No more seats available for your selection**"<<endl;

//Exit, if all first class and economy seats are filled

if(getEconomy()>=5 && getFirstClass()>=5)

{

cout<<"Reservation is closed"<<endl;

system("pause");

exit(1);

}

}

break;

case 2:

//check the availability in economy class

if(getEconomy()<5)

{

cout<<"Available seats in Economy: "<<5-getEconomy()<<endl;

resrEconomy();

cout<<"You have successfully reserved the Economy seat: "<<getEconomy()<<endl;

}

else

{

//Display that no more seats, if all economy seats are filled

cout<<"**No more seats available for your selection**"<<endl;

//Exit, if all first class and economy seats are filled

if(getEconomy()>=5 && getFirstClass()>=5)

{

cout<<"Reservation is closed"<<endl;

system("pause");

exit(1);

}

}

break;

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

}

}

};

int main()

{

int choice;

Plane ars;

cout<<"Welcome to Airline Reservation System"<<endl;

//repeats until all the seats are reserved

while(true)

{

ars.CheckIn();

}

return 0;

}

User Xlander
by
3.4k points