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: 3762618 • Letter: W

Question

Write a program to assign passengers seats in an airplane. Assume a small airplane, such as the Canadair CRJ flown by many regional airlines, is the one being used.

As shown in the figure to the left (courtesy of seatguru.com), the CRJ has a total of 50 seats, configured as 12 rows of 4 seats (with an aisle between seats B and C) and a thirteenth row (but labeled as row 14 – perhaps for triskaidekaphobic customers).

The seating should be initially shown as follows:

1 A B   C D

2 A B   C D

3 A B   C D

4 A B   C D

5 A B   C D

6 A B   C D

7 A B   C D

8 A B   C D

9 A B   C D

10 A B   C D

11 A B   C D

12 A B   C D

14 A B  

The program should display the seat pattern as shown above, with an ‘X’ marking the seats already assigned. For example, after seats 1A, 2B and 4C are assigned, the first four rows of the display should look like this:

1 X B   C D

2 A X   C D

3 A B   C D

4 A B   X D

The program is to operate as follows. After displaying the seats both available and occupied, the program allows the user to enter in a seat; the display is then updated. This continues until either all seats are filled or the user signals that the program should end. If the user types in a seat that is already assigned, the program is to indicate that the seat is occupied and to then prompt for another choice. For your programming convenience, the seating chart must be implemented using a GLOBAL 2-D character array (which means that you do not have to pass the array to functions – it is already accessible).

Explanation / Answer

#include <iostream>

#include <string>

using namespace std;

char seats[12][4];

void Initialize(){

for(int i = 0 ; i < 12 ; i++){

for(int j = 0; j < 4; j++){

seats[i][j] = 65 + j;

}

}

}

void DisplaySeats(){

for(int i = 0 ; i < 12 ; i++){

for(int j = 0; j < 4; j++){

cout<<seats[i][j]<<" ";

}

cout<<endl;

}

}

bool checkAvailability(){

for(int i = 0 ; i < 12 ; i++){

for(int j = 0; j < 4; j++){

if( seats[i][j] != 'X')

return true;

}

}

return false;

}

void BookSeat(int row,char column){

if( seats[row][column % 65] != 'X')

seats[row][column % 65] = 'X';

else

cout<<"Seat is already assigned"<<endl;

  

}

int main(){

Initialize();

int row,column;

while (checkAvailability()) {

DisplaySeats();

cout<<"Enter row:"<<endl;

cin>>row;

cout<<"Enter column:"<<endl;

cin>>column;

BookSeat(row, column);

}

DisplaySeats();

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