Answer:
The App is written in C++ language using dev C++.
Explanation:
/******************************************************************************
You can run this program in any C++ compiler like dev C++ or any online C++ compiler
*******************************************************************************/
#include <iostream>
using namespace std;
class bookingSeat// class for airline reservation system
{
private:
bool reserveSeat[10];// 10 seats (1-5) for first class and 6-10 for economy class
int firstClassCounter=0;//count first class seat
int economyClassCounter=5;//count economy class seat
char seatPlacement;/* switch between economy and first clas seat----- a variable for making decision based on user input*/
public:
void setFirstClassSeat()//
{
if(firstClassCounter<5)// first class seat should be in range of 1 to 5
{
reserveSeat[firstClassCounter]=1; /*set first class seat..... change index value to 1 meaning that it now it is reserved*/
cout<<"Your First Class seat is booked and your seat no is "<<firstClassCounter+1; //display seat number reserved
firstClassCounter++; //increament counter
}
else//in case seats are ful
{
cout<<"\nSeats are full";
if(economyClassCounter==10 && firstClassCounter==5)
{
cout<<"\n Next flight leaves in 3 hours.";
}
else
{
cout<<"\nIt’s acceptable to be placed to you in the first-class section y/n ";//take input from user
cin>>seatPlacement;//user input
if(seatPlacement=='y')//if customer want to reserve seat in first class
{
setEconomyClassSeat();// then reserve first class seat
}
else
{
cout<<"\n Next flight leaves in 3 hours.";
}
}
}
}
void setEconomyClassSeat()//set economy class seat
{
if(economyClassCounter<10)//seat ranges between 6 and 10
{
reserveSeat[economyClassCounter]=1;// reserve economy class seat
cout<<"Your Economy class seat is booked and your seat no is "<<economyClassCounter+1;//display reservation message about seat
economyClassCounter++;//increament counter
}
else// if economy class seats are fulled
{
cout<<"\nSeats are full";
if(economyClassCounter==10 && firstClassCounter==5)//check if all seats are booked in both classes
{
cout<<"\n Next flight leaves in 3 hours.";
}
else
{
cout<<"\nIt’s acceptable to be placed to you in the first-class section y/n ";//take input from user
cin>>seatPlacement;//user input
if(seatPlacement=='y')//if customer want to reserve seat in first class
{
setFirstClassSeat();// then reserve first class seat
}
else
{
cout<<"\n Next flight leaves in 3 hours.";
}
}
}
}
};
int main()
{ int checkseat=10;// check seat
int classType;//class type economy or first class
bookingSeat bookseat;//object declaration of class bookingSeat
while(checkseat<=10)//run the application until seats are fulled in both classes
{
cout<<"\nEnter 1 for First Class and 2 for Economy Class ";
cin>>classType;//what user entered
switch (classType)//decide which seat class to be reserved
{
case 1://if user enter 1 then reserve first class seat
bookseat.setFirstClassSeat();
break;
case 2://if user enter 2 then reserve the economy class seat
bookseat.setEconomyClassSeat();
}
}
return 0;
}