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

Page of 2 3. (45 points: Airline Reservations System) A small airline has just p

ID: 3753831 • Letter: P

Question

Page of 2 3. (45 points: Airline Reservations System) A small airline has just purchased a new system (capacity: 10 seats). computer for its new automated reservations system. You have been asked to develop the You are to write an application to assign seats on each flight of the airline's only plane Your application should display the following altermatives: Please type 1 for First Class and Please type 2 for Economy. If the user types 1, your application should assign a seat in the firstclass section (seats 1-5). If the user types 2, your application should assign a seat in the economy section (seats 6-10). Your application should then display a boarding pass indicating the person's seat number and whether it is in the first-class or economy section of the plane. Use a one-dimensional array of primitive type boolean 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 elements of the array to true to indicate that the seat is no longer available. Your application should never assign a seat that has alrcady been assigned. When the economy section is full, your application should ask the person if it is 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." Your output should appear as follows: Please type 1 for First Class Please type 2 for Economy choice: 1 First Class. Seat #1 Please type 1 for First Class lease type 2 for Economy

Explanation / Answer

#include <iostream>

using namespace std;

int main(int argc, char const *argv[])

{

int fClass[10]; //declaring first class array

int eClass[10]; //second class array

int i = 0, j = 0; // i ,j for counting seats

int type = 1;

//looping program while type have a positive integer

while (type) //using while loop to continue or repeat program

{

cout << "Please type 1 for First class" << endl;

cout << "Please type 2 for Economy class" << endl;

cin >> type;

if (type == 1) //choice first

{

//if (first class if full then ask for Economy class

//we i > 9 means we start counting seats from 0 it means 10 seats and we initial values in array from index 0

if (i > 9)

{

cout << "First class is full ,economy class ? " << endl;

cout << "1. Yes 2. NO. ,Your choice :";

int choice;

cin >> choice;

if (choice == 1)

{ //check first and second class is full or not

if (j > 9) // when first and second class is full

cout << "Next flight leaves in next 3 hours" << endl;

//when first class seats is available

else

{

eClass[j] = 1;

j++;

cout << "Economy class seat #" << j;

}

}

else

cout << "Next flight leaves in next 3 hours" << endl;

}

else

{

fClass[i] = 1;

i++;

cout << "Firs class seat #" << i << endl;

}

}

if (type == 2)

{

if (j > 9)

{

cout << "Economy class is full ,first class ? " << endl;

cout << "1. Yes 2. NO. ,Your choice :";

int choice;

cin >> choice;

if (choice == 1)

{

if (i > 9)

cout << "Next flight leaves in next 3 hours" << endl;

else

{

fClass[i] = 1;

i++;

cout << "First class seat #" << i << endl;

}

}

else

cout << "Next flight leaves in next 3 hours" << endl;

}

else

{

eClass[j] = 1;

j++;

cout << "Economy class seat #" << j<<endl;

}

}

cout<<"-----------------------------------------------------"<<endl;

cout<<"--------------------THank you------------------------"<<endl;

cout<<endl<<endl<<endl;

cout<<"Please Type 1. for continue 0. for exit"<<endl;

cin>>type;

}

return 0;

}