Write a program to assign passengers seats in an airplane As

Write a program to assign passengers seats in an airplane. Assume a small airplane with seat numbering as follows: A B C D A B C D A B C D A B C D A B C D A B C D A B C D The program should display the seat pattern, with an \'X\' marking the seats already assigned. For example, after seats 1A, 2B, and 4C are taken, the display should look like this X B C D A X C D A B C D A B X D A B C D A B C D A B C D After displaying the seats available. The program prompts for the seat desired, the user types in a seat, and then the display of available seats is updated. This continues until all seats are filled or until the user signals that program should end. If the user types in a seat that is already assigned. The program should say that seat is occupied and ask for another choice.

Solution

#include <iostream>

#include <string>

using namespace std;

int main()

{

    char Seat = \' \';

    string Airline[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(Airline[Row-1][idx] == \'X\') { //checks if seat is taken or not

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

                               continue; }

                        else

                               Airline[Row - 1][idx] = \'X\';

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

                               cin >> Again;

                              

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

               {

                                               cout << Airline[i] << endl;

               }

              

    } //end while

  

    cout << \"Bye!\" << endl;

  

    system(\"PAUSE\");

    return 0;

}

 Write a program to assign passengers seats in an airplane. Assume a small airplane with seat numbering as follows: A B C D A B C D A B C D A B C D A B C D A B
 Write a program to assign passengers seats in an airplane. Assume a small airplane with seat numbering as follows: A B C D A B C D A B C D A B C D A B C D A B

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site