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.  Use two parallel arrays: a one-dimensional array to store the row number of the seats (Row #) a two-dimensional array of 13 rows and 6 columns to store the seat assignments (*) and seat letters (A-F) Your program must prompt the user to enter the following information: Reserve a seat (Yes (Y/y) or No (N/n)) Assign ticket type (first class (F/f), business class (B/b), or economy class (E/e)) Select desired seat (1-13 and A-F) Your program must contain at least the following functions: a function to initialize the seat plan. a function to show the seat assignments. a function to show the menu to assign a seat. a function to assign and select your desired seat. a function for each ticket type that determines if a seat is occupied and if that class is full . Output the seating plan in the following form:             A  B  C  D Row 1  *  X   *   * Here, * indicates that the seat is available; Xindicates 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. The past two times i have asked this question the answer was inncorect the choice for it being Y or y in the begining to ask if the user wanted to reserve a seat on the program was not there. Also the input when they sleect a seat needs to follow the instructions given to F or f and so on and so forth. And at the end of the program, it needs to be able to restart if the user wants to select another seat.

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 16PE
icon
Related questions
Question

(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. 

Use two parallel arrays:

  • a one-dimensional array to store the row number of the seats (Row #)
  • a two-dimensional array of 13 rows and 6 columns to store the seat assignments (*) and seat letters (A-F)

Your program must prompt the user to enter the following information:

  • Reserve a seat (Yes (Y/y) or No (N/n))
  • Assign ticket type (first class (F/f), business class (B/b), or economy class (E/e))
  • Select desired seat (1-13 and A-F)

Your program must contain at least the following functions:

  • a function to initialize the seat plan.
  • a function to show the seat assignments.
  • a function to show the menu to assign a seat.
  • a function to assign and select your desired seat.
  • a function for each ticket type that determines if a seat is occupied and if that class is full .

Output the seating plan in the following form:

            A  B  C  D

Row 1  *  X   *   *

Here, * indicates that the seat is available; Xindicates 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.

The past two times i have asked this question the answer was inncorect the choice for it being Y or y in the begining to ask if the user wanted to reserve a seat on the program was not there. Also the input when they sleect a seat needs to follow the instructions given to F or f and so on and so forth. And at the end of the program, it needs to be able to restart if the user wants to select another seat.

Expert Solution
Step 1

Program:

 

#include <iostream>
#include <iomanip>
#include <string>
#include <cctype>
#include <cstring>
using namespace std;

const int NUMROWS = 14;
const int NUMSEATS = 7;
//enum seatsType {A,B,C,D,E,F};

void initPlane(char plane[NUMROWS][NUMSEATS])
{
     int x,y;
     //strcpy(plane[2], "Row 1");
     plane[0][0] = ' ';
     plane[0][1] = 'A';
     plane[0][2] = 'B'; 
     plane[0][3] = 'C';
     plane[0][4] = 'D';
     plane[0][5] = 'E';
     plane[0][6] = 'F';
     plane[1][0] = '1';
     plane[2][0] = '2';
     plane[3][0] = '3';
     plane[4][0] = '4';
     plane[5][0] = '5';
     plane[6][0] = '6';
     plane[7][0] = '7';
     plane[8][0] = '8';
     plane[9][0] = '9';
     plane[10][0] = 'W';
     plane[11][0] = 'Y';
     plane[12][0] = 'Z';
     plane[13][0] = 'G';
     for (x = 1; x < NUMROWS ; x++)
     {
         for ( y = 1 ; y < NUMSEATS ; y++)
         plane[x][y] = '*';
     }
}
// POSTCONDITION: 
//   plane[x][0] == 'A', 0<=x<13
//   plane[x][1] == 'B', 0<=x<13
//   plane[x][2] == 'C', 0<=x<13
//   plane[x][3] == 'D', 0<=x<13


void printPlane(char msg[], char plane[NUMROWS][NUMSEATS])
{
     cout << msg << endl;
     int Row,col;
     for ( Row = 0; Row < NUMROWS ; Row ++)
     {
         for (col = 0; col < NUMSEATS; col++)
         cout << setw(5) << plane [Row][col] << " ";
         cout << endl;
     }
}
// POSTCONDITION: The seating layout of the plane has been printed
// to the standard output with an X displayed for each taken seat.


int main()
{
  int seatsTaken = 0;
  int seats = NUMROWS * NUMSEATS;
  char plane[NUMROWS][NUMSEATS];
  char keepGoing = 'y';
  int row = 0; 
  char seat;
  int rowIndex, seatIndex;
  char ticketType[15];

   initPlane(plane);

  cout << "Choose your seat!" << endl;
  while (seatsTaken < seats && keepGoing == 'y')
    {
      //
      // Show layout and get seat choice
      // 
      printPlane("Plane layout; X designates taken seats", plane);
      cout << "Row 1 and 2 are first clss. " << endl;
      cout << "Rows 3 through 7 are business class. " << endl;
      cout << "Rows 8 through 13 are economy class. " << endl;
      cout << "Eneter ticket type (first class,business class,or economy class) :" ;
      cin >> row >> seat;
           

      
      // Adjust input to use as indices
      
      rowIndex = row;
      
      
      if ( seat == 'A' || seat == 'a' )
      seatIndex = 1;
      else if ( seat == 'B' || seat == 'b' )
      seatIndex = 2;
      else if ( seat == 'C' || seat == 'c' )
      seatIndex = 3;
      else if ( seat == 'D' || seat == 'd' )
      seatIndex = 4;
      else if ( seat == 'E' || seat == 'e' )
      seatIndex = 5;
      else if ( seat == 'F' || seat == 'f' )
      seatIndex = 6;
      
      

      //
      // Check to see if seat is taken
      // 
      if (plane[rowIndex][seatIndex] == 'X')
 cout << "Sorry, " << row << seat << " is already taken." << endl;
      else
 {
   cout << "OK, you've got " << row << seat << endl;
   plane[rowIndex][seatIndex] = 'X';
   seatsTaken++;
 }

      //
      // If there are seats left, check we should keep going
      // 

      if (seatsTaken < seats)
 {
 cout << "Choose another seat? (y/n) ";
 cin >> keepGoing;
 }
      else
 cout << "Plane is now full!" << endl;
    }

    printPlane("Final seating chart", plane);
    
    return 0;
    
}

//Here * indicates the seat available, X indicates the seat occupied . Make a menu driven program ; the show the user the choises and allow to make appropriate choices.

trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 1 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Programming with Microsoft Visual Basic 2017
Programming with Microsoft Visual Basic 2017
Computer Science
ISBN:
9781337102124
Author:
Diane Zak
Publisher:
Cengage Learning
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage