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

Working code without any errors a. b. Sufficient comments for user to read your

ID: 3757815 • Letter: W

Question

Working code without any errors a. b. Sufficient comments for user to read your code and analyze your logic. c. Proper indentation. d. Proper use of variables and identifiers. e. Use of Functions, array, loop, conditional stalemates. f. Submit your working code before the deadline. Program 16/Chapter 8 (Airplane Seating Assignment) Write a program that can be used to assign seats for a commercial airplane. The airplane has 13 rows, with six seats in each row Rows 1 and 2 are first class, rows 3 through 7 are business class, and rows 8 through 13 are economy class. Your program must prompt the user to enter the following information: a. Ticket type (first class, business class, or economy class) b. Desired seat Output the seating plan in the following form: Row 1 Row 2 Row 3 Row 4 Row 5 Row 6 Row 7 Row 8 Row 9 Row 10 Row 11 Row 12 Row 13 Here, * indicates that the seat is available; X indicates that the seat is occupied. Make this a menu-driven program; show the user's choices and allow the user to make the appropriate choices.

Explanation / Answer

#include <iostream>
#include <string>
#include <ctype.h>

using namespace std;

void initialiseSeats();
void fillupSeat(int row, int col);
void bookTkt();
void displaySeats();
int displayMenu();

//global variable to maintain seats
char seats[13][6];

int main() {

   initialiseSeats();

   int option = 0;
   while(option !=3) {
       option = displayMenu();

       if(option == 1) {
           bookTkt();
       } else if(option == 2) {
           displaySeats();
       } else if(option == 3) {
           break;
       } else {
           cout << "Invalid option"<<endl;
       }
   }
}

void initialiseSeats() {
   int i , j;
   for(i = 0; i < 13; i++) {
       for(j = 0; j < 6; j++) {
           seats[i][j] = '*'; // * indicates seat available
       }
   }
}

void fillupSeat(int row, int col) {
   if(seats[row-1][col-1] == 'X')
       cout << "Seat already booked" <<endl;
   else
       seats[row-1][col-1] = 'X'; // X - indicates seat is filled up
}

void bookTkt() {

   int row = 0;
   int tktclass = 0;
   int column = 0;
   cout << "Ticket Type: " <<endl;
   cout << "1. First Class 2. Business Class 3. Economy Class" <<endl;
   cout << "Enter option: "<<endl;

   do {
       cin >> tktclass;
       if(tktclass >=1 && tktclass <=3)
           break;
       else
           cout << "Enter valid option:" <<endl;
   } while(tktclass <1 || tktclass > 3);

   cout << "Choose Seat: " <<endl;

   bool isValidRow = false;
   if(tktclass == 1) {
       cout << "Enter Row[1 or 2]: "<<endl;
       cin >> row;
       if(row == 1 || row == 2)
           isValidRow = true;
   } else if(tktclass == 2) {
       cout << "Enter Row[3 to 7]: "<<endl;
       cin >> row;
       if(row >=3 && row <=7)
           isValidRow = true;
   } else if(tktclass == 3) {
       cout << "Enter Row[8-13]: "<<endl;
       cin >> row;
       if(row >=8 && row <=13)
           isValidRow = true;
   }


   if(isValidRow) {
       cout << "Enter Column (A to F): "<<endl;
       char colstr;
       cin >> colstr;
       column = (int)( tolower(colstr) - 'a')+1;

       if(row >=1 && row <=13 && column >=1 && column <= 6) {

           fillupSeat(row, column);
       } else {
           cout << "Invalid Column" <<endl;
       }

   } else {
       cout << "Invalid row" <<endl;
   }




}

int displayMenu() {
   cout << " Menu: " << endl;
   cout <<"1. Book Ticket" <<endl;
   cout <<"2. Show seating arrangement" <<endl;
   cout <<"3. Exit" <<endl;
   cout <<" Enter your option: "<<endl;
   int option = 0;
   do {
       cin >> option;
       if(option >=1 && option <=3)
           break;
       else
           cout << "Enter valid option:" <<endl;
   } while(option <1 || option > 3);

   return option;

}

void displaySeats() {

   int i , j;
   //display header and values = 1+13 = 14 rows, 1+6 = 7 columns
   //display ro header
   cout << " A B C D E F" << endl;
   for(i = 0; i < 13; i++) {
       for(j = 0; j < 7; j++) {


           if(j == 0) {
               //row name
               cout <<"Row " <<(i+1)<<" ";
           } else {
               cout << seats[i][j-1]<<" ";
           }

       }
       cout <<endl;
   }
}

--------output--------------


Menu:

1. Book Ticket
2. Show seating arrangement
3. Exit

Enter your option:
2
   A   B   C   D   E   F
Row 1    *    *    *    *    *    *   
Row 2    *    *    *    *    *    *   
Row 3    *    *    *    *    *    *   
Row 4    *    *    *    *    *    *   
Row 5    *    *    *    *    *    *   
Row 6    *    *    *    *    *    *   
Row 7    *    *    *    *    *    *   
Row 8    *    *    *    *    *    *   
Row 9    *    *    *    *    *    *   
Row 10    *    *    *    *    *    *   
Row 11    *    *    *    *    *    *   
Row 12    *    *    *    *    *    *   
Row 13    *    *    *    *    *    *   

Menu:

1. Book Ticket
2. Show seating arrangement
3. Exit

Enter your option:
1
Ticket Type:
1. First Class
2. Business Class
3. Economy Class
Enter option:
1
Choose Seat:
Enter Row[1 or 2]:
1
Enter Column (A to F):
A

Menu:

1. Book Ticket
2. Show seating arrangement
3. Exit

Enter your option:
2
   A   B   C   D   E   F
Row 1    X    *    *    *    *    *   
Row 2    *    *    *    *    *    *   
Row 3    *    *    *    *    *    *   
Row 4    *    *    *    *    *    *   
Row 5    *    *    *    *    *    *   
Row 6    *    *    *    *    *    *   
Row 7    *    *    *    *    *    *   
Row 8    *    *    *    *    *    *   
Row 9    *    *    *    *    *    *   
Row 10    *    *    *    *    *    *   
Row 11    *    *    *    *    *    *   
Row 12    *    *    *    *    *    *   
Row 13    *    *    *    *    *    *   

Menu:

1. Book Ticket
2. Show seating arrangement
3. Exit

Enter your option:
1
Ticket Type:
1. First Class
2. Business Class
3. Economy Class
Enter option:
3
Choose Seat:
Enter Row[8-13]:
12
Enter Column (A to F):
F

Menu:

1. Book Ticket
2. Show seating arrangement
3. Exit

Enter your option:
2
   A   B   C   D   E   F
Row 1    X    *    *    *    *    *   
Row 2    *    *    *    *    *    *   
Row 3    *    *    *    *    *    *   
Row 4    *    *    *    *    *    *   
Row 5    *    *    *    *    *    *   
Row 6    *    *    *    *    *    *   
Row 7    *    *    *    *    *    *   
Row 8    *    *    *    *    *    *   
Row 9    *    *    *    *    *    *   
Row 10    *    *    *    *    *    *   
Row 11    *    *    *    *    *    *   
Row 12    *    *    *    *    *    X   
Row 13    *    *    *    *    *    *   

Menu:

1. Book Ticket
2. Show seating arrangement
3. Exit

Enter your option:
3

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