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

Write a program to assign passengers seats in an airplane. Assume a small airpla

ID: 3815338 • Letter: W

Question

Write a program to assign passengers seats in an airplane. Assume a small airplanewith seat numbering as follows:1 A B C D2 A B C D3 A B C D4 A B C D5 A B C D6 A B C D7 A B C DYour program will ask the user how many rows the plane has and use a dynamicarray or arrays) to handle the number of rows. Your program should display theseat pattern, with an X marking the seats already assigned. For example, after seats1A, 2B, and 4C are taken, the display should look like this:1 X B C D2 A X C D3 A B C D4 A B X D5 A B C D6 A B C D7 A B C DAfter displaying the seats available, the program prompts for the seat desired, theuser types in a seat, and then the display of available seats is updated. Thiscontinues until all seats are filled or until the user signals that the program shouldend. If the user types in a seat that is already assigned, the program should say thatthe seat is occupied and ask for another choice. Don’t forget to free the memoryallocated for these returned dynamic arrays when the data is no longer needed.(Automated testing) For a large number of rows, you may need to enter a lot of testdata. In order to speed up the testing, you need to design your program to allow theinput to be entered via console or an input file. So you should initially prompt the

user to ask whether the input will come from the console or an input file. If from aninput file, user needs to enter the file name. For example, the test file should containthe following input:71A2A3A4A5A6A7A2B2C2D…7DendYou can have different test files, with some containing conflicting seat assignments.

Explanation / Answer

#include <iostream>

#include <string>

using namespace std;

int main()

{

    char Seat = ' ';

    string AirplaneSeat[7] = {"1ABCD", "2ABCD", "3ABCD", "4ABCD", "5ABCD", "6ABCD", "7ABCD"};

    char Again = ' ';

    int Row = 0;

    Again = 'y';

    while(Again == 'y')

    {

                cout << "Enter a row: ";

                cin >> Row;

                cout << "Enter a seat: ";

                cin >> Seat;

              

                        int idx = 1 + Seat - 'A';

                        if(AirplaneSeat[Row-1][idx] == 'X')

                       {                                

                               cout << "Seat is taken." << endl;

                               continue;

                       }

                        else

                               AirplaneSeat[Row - 1][idx] = 'X';

                               cout << "Enter another seat? (y/n): ";

                               cin >> Again;

                              

               for(int i=0; i<7; ++i)

               {

                              cout << AirplaneSeat[i] << endl;

               }

              

    }

  

    cout << "Bye!" << endl;

  

    system("PAUSE");

    return 0;

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote