Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hi I'm trying to understand why my code works but doesn't work for a grade, how to fix it and if you could show the

Hi I'm trying to understand why my code works but doesn't work for a grade, how to fix it and if you could show the corrected code, why its not working this is for C++.

(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: Seating Plan Here, * indicates that the seat is available; X indicates that the seat is occupied. Make this a menu-driven program; show the users choices and allow the user to make the appropriate choices.

#include

#include

using namespace std;

// Prints Seats Status Onto The Console

void printSeats(char A[13][6]) {

cout << " A B C D E F" << endl;

for (int r = 0; r < 13; r++) {

cout << "Row" << setw(3) << r + 1 << " ";

for (int c = 0; c < 6; c++) {

cout << A[r][c] << ' ';

}

cout << endl;

}

}

// Book A Seat

void book(char A[13][6], int rowMin, int rowMax) {

// For Row And Column Input From User

int row;

char col;

// Input Row And Column

cout << "Enter Row(" << rowMin << "-" << rowMax << "): ";

cin >> row;

cout << "Enter Column(A-F): ";

cin >> col;

// Convert Column To Uppercase

col = toupper(col);

// Check If A Valid Seat

if (row >= rowMin && row <= rowMax && col >= 'A' && col <= 'F') {

// Check If Seat is Empty

if (A[row - 1][col - 65] == '*') {

// Book It

cout << "Seat booked." << endl;

A[row - 1][col - 65] = 'X';

} else {

// Already Booked

cout << "Sorry, this seat is already booked." << endl;

}

} else {

// Invalid Seat

cout << "Invalid seat." << endl;

}

cout << endl;

}

int main() {

// 3D Array To Keep Track Of Seat Availability

char A[13][6];

// Print Welcome Message

cout << "A program that lets you choose your seating arrangement on an airplane" << endl;

// Initial All Seats To Be Empty

for (int r = 0; r < 13; r++) {

for (int c = 0; c < 6; c++)

A[r][c] = '*';

}

// User's Choice To Book More Seats

char bookMore;

// Ticket Type

char ticketType;

// User Can Book A Seat As Long As He Likes

do {

printSeats(A);

cout << endl

<< "* -- Available Seat" << endl

<< "X -- Occupied Seat" << endl

<< endl

<< "Rows 1 and 2 are for first class passengers." << endl

<< "Rows 3 through 7 are for business class passengers." << endl

<< "Rows 8 through 13 are for economy class passengers." << endl

<< endl;

// Input Ticket Type From The User

cout << "E: Economy Class" << endl

<< "B: Business Class" << endl

<< "F: First Class" << endl << endl

<< "Input ticket type: ";

cin >> ticketType;

// Switch On TicketType

switch (ticketType) {

// Economy Class

case 'E':

case 'e':

book(A, 8, 13);

break;

// Business Class

case 'B':

case 'b':

book(A, 3, 7);

break;

// First Class

case 'F':

case 'f':

book(A, 1, 2);

break;

// Invalid Choice

default:

cout << "Invalid ticket type.";

break;

}

// Ask User If He Wants To Book More Seats

cout << "Book More? (Yy/Nn):";

cin >> bookMore;

cout << endl;

} while (bookMore == 'Y' || bookMore == 'y');

printSeats(A);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions

Question

LO6 Describe how individual pay rates are set.

Answered: 1 week ago