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

Write a program that can be used to assign seats for a commcommercial airplane.

ID: 3690193 • Letter: W

Question

Write a program that can be used to assign seats for a commcommercial airplane. The airplane has 13 rows, with 6 seats in each row. Rows 1 and 2 are first class, rows 3 to 7 are business class, and rows 8 to 13 are economy class. Your program prompts 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 format: A B C D E F

Row 1 * * X * X X

Row 2 * X * X * X

Row 3 * * X X * X

Row 4 X * X * X X

Row 5 * X * X * *

Row 6 * X * * * X

Row 7 X * * * X X

Row 8 * X * X X *

Row 9 * * X * X X

Row 10 * X * X X X

Row 11 * * X * X *

Row 12 * * X X * X

Row 13 * * * * X *

Here, * indicates that the seat is available; x indicates that the seat has been assigned. Make this a menu driven program; show the user's choices and allow the user to make the appropriate choices.Beginning with this assignment and including all subsequent assignments ... do not assume that you will recieve "good data" (ie. your program must inspect all input data to ensure that it is valid, and take appropriate action if it is not). Your program should begin by presenting a menu that has (at a minimum) the following items to choose from: "Assign a Seat"; "Cancel a Reservation"; "Print the Seating Chart"; and "Exit the Program". Once a selection is made, process that selection. You may break down the "Assign a Seat" menu item into three separate choices ... "Assign a First Class Seat"; "Assign a Business Class Seat"; and "Assign an Economy Seat" ... if you like. Your should only print the seating chart when that selection is chosen from the menu.

***ANSWER MUST NOT UTILIZE LIBRARY "include <cctype>" AS IT ISNT COVERED IN TEXTBOOK.

Explanation / Answer

/** C99 code  to assign seats for a commcommercial airplane **/

#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <fstream>
using namespace std;

#define Row 13
#define Column 6


void initialize(char Aeroplane[][6])
{
   for (int i = 0; i < Row; ++i)
   {
       for (int j = 0; j < Column; ++j)
       {
           Aeroplane[i][j] = '*';
       }
   }
}

void assign_seat(char Aeroplane[][6])
{
   int choice;
   cout << " 1.Assign a First Class Seat 2.Assign a Business Class Seat 3.Assign an Economy Seat ";
   cout << "Enter your choice: ";
   cin >> choice;

   if(choice == 1)
   {
       int r;
       char ch;
       int c;
       cout << "Rows 1 and 2 are first class, enter coordinates of your seat to reserve ";
       cout << "Enter Row: ";
       cin >> r;
       cout << "Seating A B C D E F: ";
       cin >> ch;
       cin.ignore();
       if(ch == 'A') c = 0;
       else if(ch == 'B') c = 1;
       else if(ch == 'C') c = 2;
       else if(ch == 'D') c = 3;
       else if(ch == 'E') c = 4;
       else if(ch == 'F') c = 5;

       while(Aeroplane[r-1][c] == 'X')
       {
           cout << "Seat already reserved, select another seat. ";
           cout << "Enter Row: ";
           cin >> r;
           cout << "Seating A B C D E F: ";
           cin >> ch;
           cin.ignore();
           if(ch == 'A') c = 0;
           else if(ch == 'B') c = 1;
           else if(ch == 'C') c = 2;
           else if(ch == 'D') c = 3;
           else if(ch == 'E') c = 4;
           else if(ch == 'F') c = 5;
       }

       Aeroplane[r-1][c] = 'X';
   }

   else if(choice == 2)
   {
       int r;
       char ch;
       int c;
       cout << "Rows 3-7 are business class, enter coordinates of your seat to reserve ";
       cout << "Enter Row: ";
       cin >> r;
       cout << "Seating A B C D E F: ";
       cin >> ch;
       cin.ignore();
       if(ch == 'A') c = 0;
       else if(ch == 'B') c = 1;
       else if(ch == 'C') c = 2;
       else if(ch == 'D') c = 3;
       else if(ch == 'E') c = 4;
       else if(ch == 'F') c = 5;

       while(Aeroplane[r-1][c] == 'X')
       {
           cout << "Seat already reserved, select another seat. ";
           cout << "Enter Row: ";
           cin >> r;
           cout << "Seating A B C D E F: ";
           cin >> ch;
           cin.ignore();
           if(ch == 'A') c = 0;
           else if(ch == 'B') c = 1;
           else if(ch == 'C') c = 2;
           else if(ch == 'D') c = 3;
           else if(ch == 'E') c = 4;
           else if(ch == 'F') c = 5;
       }

       Aeroplane[r-1][c] = 'X';
   }
   else if(choice == 3)
   {
       int r;
       char ch;
       int c;
       cout << "Rows 8-13 are economy class, enter coordinates of your seat to reserve ";
       cout << "Enter Row: ";
       cin >> r;
       cout << "Seating A B C D E F: ";
       cin >> ch;
       cin.ignore();
       if(ch == 'A') c = 0;
       else if(ch == 'B') c = 1;
       else if(ch == 'C') c = 2;
       else if(ch == 'D') c = 3;
       else if(ch == 'E') c = 4;
       else if(ch == 'F') c = 5;

       while(Aeroplane[r-1][c] == 'X')
       {
           cout << "Seat already reserved, select another seat. ";
           cout << "Enter Row: ";
           cin >> r;
           cout << "Seating A B C D E F: ";
           cin >> ch;
           cin.ignore();
           if(ch == 'A') c = 0;
           else if(ch == 'B') c = 1;
           else if(ch == 'C') c = 2;
           else if(ch == 'D') c = 3;
           else if(ch == 'E') c = 4;
           else if(ch == 'F') c = 5;
       }
       Aeroplane[r-1][c] = 'X';
   }

   cout << "Seat Reserved ";
}

void print_chart(char Aeroplane[][6])
{
   for (int i = 0; i < Row; ++i)
   {
       printf("Row %d ",i+1);
       for (int j = 0; j < Column; ++j)
       {
           printf("%c",Aeroplane[i][j]);
       }
       printf(" ");
   }
}

void cancel_seat(char Aeroplane[][6])
{
       int r;
       char ch;
       int c;
       cout << "Enter Row: ";
       cin >> r;
       cout << "Seating A B C D E F: ";
       cin >> ch;
       if(ch == 'A') c = 0;
       else if(ch == 'B') c = 1;
       else if(ch == 'C') c = 2;
       else if(ch == 'D') c = 3;
       else if(ch == 'E') c = 4;
       else if(ch == 'F') c = 5;

       Aeroplane[r-1][c] = '*';

}

int main()
{
   char Aeroplane[Row][Column];
   initialize(Aeroplane);
   while(true)
   {
       int choice;
       cout << " 1.Assign a Seat 2.Cancel a Reservation 3.Print the Seating Chart 4.Exit the Program ";
       cout << "Enter your choice: ";
       cin >> choice;

       if(choice == 1) assign_seat(Aeroplane);
       else if(choice == 2) cancel_seat(Aeroplane);
       else if(choice == 3) print_chart(Aeroplane);
       else return 0;
   }

   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