53.0k views
0 votes
8.19 - Airline Reservations System (Project Name: Airline) - A small airline has just purchased a computer for its new automated reservations system. You have been asked to develop the new system. You’re to write an app to assign seats on each flight of the airline’s only plane (capacity: 10 seats). Display the following alternatives: Please enter 1 for First Class or 2 for Economy. If the user types 1, your app should assign a seat in the first-class section (seats 1–5). If the user types 2, your app should assign a seat in the economy section (seats 6–10). Use a one-dimensional array of type bool to represent the seating chart of the plane. Initialize all the elements of the array to false to indicate that all the seats are empty. As each seat is assigned, set the corresponding element of the array to true to indicate that the seat is no longer available. Your app should never assign a seat that has already been assigned. When the economy section is full, your app should ask the person if it’s acceptable to be placed in the first-class section (and vice versa). If yes, make the appropriate seat assignment. If no, display the message "Next flight leaves in 3 hours."

User Jia
by
5.7k points

1 Answer

4 votes

Answer:

The App is written in C++ language using dev C++.

Step-by-step 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<<"\\Seats are full";

if(economyClassCounter==10 && firstClassCounter==5)

{

cout<<"\\ Next flight leaves in 3 hours.";

}

else

{

cout<<"\\It’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<<"\\ 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<<"\\Seats are full";

if(economyClassCounter==10 && firstClassCounter==5)//check if all seats are booked in both classes

{

cout<<"\\ Next flight leaves in 3 hours.";

}

else

{

cout<<"\\It’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<<"\\ 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<<"\\Enter 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;

}

User Aman Mundra
by
5.2k points