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

solve it using C++ Program plz Exercise 3: Airline Reservation Svstem A very sma

ID: 3694931 • Letter: S

Question

solve it using C++ Program plz

Exercise 3: Airline Reservation Svstem A very small airline owns a small aircraft with a capacity of 10 seats. Write a C++ program that keeps track of flight reservations. Your program should display the following Would you like to make a reservation? Enter Y or y for yes or N or n for no. (Your program executes until the user answers no). Each time the user answers yes, the following menu should be displayed: Please type 1 for smoking Please type 2 for nonsmoking If the person types 1, then your program should assign a seat in the smoking section (seats 1-5). If the person types 2, then the program should assign a seat in the section 6-10. Your program should then print a boarding pass indicating the seat number and whether it is in the smoking or the nonsmoking section. Use an array to represent the seating chart of the airplane. Initialize all the elements of the array to zero indicating that all seats are available. As each seat is assigned, set the corresponding element to 1 to indicate that the seat is no longer available. Your program should never assign a seat that has already been assigned. When the smoking section is full your program should display the message "Sorry, the smoking area is full. Try the nonsmoking area". Similarly, if the nonsmoking section is full, your program should display "Sorry, the nonsmoking area is full. Try the smoking area". The program teminates when 10 seats are reserved.

Explanation / Answer

/** C++ code that keeps track of flight reservations **/

#include <iostream>
#include <stdlib.h>

using namespace std;


int main()
{
int seats[10] = {0};
int count = 0;
char ch;
int smoking = 0;
int non_smoking = 0;
int choice;

while(true)
{
cout << "Would you like to make a reservation? Enter Y or y for Yes or N or n for No: ";
cin >> ch;

if (ch == 'Y' || ch == 'y')
{
cout << "Please type 1 for smoking, 2 for non-smoking: ";
cin >> choice;

if(choice == 1)
{
if(smoking != 5)
{
seats[smoking] = 1;
smoking++;
cout << "Seat: " << smoking << " Area: Smoking ";
}

else cout << "Sorry, the smoking area is full, try the nonsmoking area ";
}

if(choice == 2)
{
if(non_smoking != 5)
{
seats[5+non_smoking] = 1;
non_smoking++;
cout << "Seat: " << non_smoking << " Area: NonSmoking ";
}

else cout << "Sorry, the nonsmoking area is full, try the smoking area ";
}

}

if(smoking == 5 && non_smoking ==5)
{
cout << "All seats occupied ";
return 0;
}

if (ch == 'N' || ch == 'n')
{
return 0;
}
}

return 0;
}