A small airline has just purchased a computer for its new automated reservations
ID: 3641614 • Letter: A
Question
A small airline has just purchased a computer for its new automated reservations system. You have been asked to develop the new system. You are to write an application to assign seats on each flight of the airline’s only plane (capacity: 10 seats).Your application should display the following alternatives: 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 already 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."
Explanation / Answer
#include <iostream>
using namespace std;
int main() {
bool full = false;
int seat;
int people = 0;
bool seating[10];
for (int i = 0; i < 10; ++i) {
seating[i] = false;
}
while(!full) {
cout << "Please type 1 for First Class and Please type 2 for Economy: ";
cin >> seat;
int where = -1;
if(seat == 1) {
for(int i = 0; i < 5; ++i) {
if(!seating[i]) {
seating[i] = true;
where = i + 1;
people++;
i = 5;
}
}
if(where < 0) {
cout << "First Class is full, would you like a seat in Economy(Y/N)? ";
char change;
cin >> change;
if(change == 'Y') {
for(int i = 5; i < 10; ++i) {
if(!seating[i]) {
seating[i] = true;
where = i + 1;
people++;
i = 10;
}
}
}
else {
cout << "Next flight leaves in 3 hours." << endl;
}
}
}
if(seat == 2) {
for(int i = 5; i < 10; ++i) {
if(!seating[i]) {
seating[i] = true;
where = i + 1;
people++;
i = 10;
}
}
if(where < 0) {
cout << "Economy is full, would you like a seat in First Class(Y/N)? ";
char change;
cin >> change;
if(change == 'Y') {
for(int i = 0; i < 5; ++i) {
if(!seating[i]) {
seating[i] = true;
where = i + 1;
people++;
i = 10;
}
}
}
else {
cout << "Next flight leaves in 3 hours." << endl;
}
}
}
if (where > 0) {
cout << "Boarding Pass" << endl;
cout << "Seat number " << where << " in ";
if(where < 6) {
cout << "First Class" << endl;
}
else {
cout << "Economy" << endl;
}
}
if(people >= 10) {
full = true;
}
}
cout << "The flight is now full" << endl;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.