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