Write a program that can be used to assign seats for a comm commercial airplane.
ID: 3532163 • 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.
note: plz do this by following my instructions everytime the solution u gave me was not following my instructions
Explanation / Answer
#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;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.