Question: Write a program that reserves seats for a theater, airline, etc. using a two-dimensional array. The program should start by asking for the number of

Write a program that reserves seats for a theater, airline, etc. using a two-dimensional array. The program should start by asking for the number of rows and seats on each row and display the available seats. The rows are to be identified by a number starting at '1'. The seats on each row are to be identified by a letter, 'A', 'B', 'C', etc. For example, 3C, 4A and 2D are sample seat identifiers.

Because the total number of rows and seats is unknown when the program first starts, it will be necessary for the program to dynamically allocate memory for the seating array and then release that memory when the program is ready to end.

The program should ask the user to select row and seat. The program needs to verify and process only legal row and seat requests. If the seat is already reserved, the program should notify the user that the seat is taken. If the seat is available, the program should replace the seat identifier with a dash character '-'. The program should contain a loop to ask if additional seats are to be reserved. The program should also give a message when all the seats are taken. A counter can be used to keep track of the total number of seats purchased.

#include

#include

using namespace std;

char ** CreateArrayOfSeats (int NumberRows, int seats);

void InitializeSeats (char **ArrayOfSeats, int NumberRows, int seats);

void DisplaySeats (char **ArrayOfSeats, int NumberRows, int seats);

void MemoryCleanup (char **ArrayOfSeats, int NumberRows, int seats);

int main(int argc, char * argv[]) {

char **ArrayOfSeats;

char rowSelect;

char seatSelect;

char answer;

int NumberRows;

int NumberSeats;

int row;

int seat;

cout << "Welcome to your personalized seating reservation system!" << endl;

cout << "Please enter the number of rows: ";

cin >> NumberRows;

cout << "Please enter the number of seats in each row: ";

cin >> NumberSeats;

ArrayOfSeats = CreateArrayOfSeats(NumberRows, NumberSeats);

InitializeSeats(ArrayOfSeats, NumberRows, NumberSeats);

DisplaySeats(ArrayOfSeats, NumberRows, NumberSeats);

do {

cout << endl;

cout << "Please enter a seat selection (Example 5F): " << endl;

cin >> rowSelect;

cin >> seatSelect;

if (rowSelect== '0')

continue;

seatSelect = toupper(seatSelect);

row = rowSelect - '1';

seat = seatSelect - 'A';

/// write the rest of the code here

////// verify if a valid row and seat were entered

////// see if all the seats are taken, keep a count (use a counter) each time a seat is taken

if (ArrayOfSeats[row][seat] == '-')

cout << "The seat you selected has already been taken, please try another seat." <

else

ArrayOfSeats[row][seat] = '-';

cout << "Do you want to select another seat (y/n)?" <

cin >> answer;

answer = toupper(answer);

} while (rowSelect != '0');

MemoryCleanup(ArrayOfSeats, NumberRows, NumberSeats);

cout << "Press the ENTER key to continue.";

char buff[100];

cin.getline (buff, 100);

return 0;

}

//// CreatArrayOfSeats Function

char **CreateArrayOfSeats (int NumberRows, int seats) {

char **ArrayOfSeats;

ArrayOfSeats = new char*[NumberRows];

for (int r=0; r

ArrayOfSeats[r] = new char[seats];

return ArrayOfSeats;

}

///// InitializeSeats Function

void INitializeSeats (char **ArrayOfSeats, int NumberRows, int seats) {

for (int r=0; r

for (int s=0; s

ArrayOfSeats[r][s] = 'A' + s;

}

}

///// DisplaySeats Function

void DisplaySeats (char **ArrayOfSeats, int NumberRows, int NumberSeats) {

for (int r=0; r

cout.width(2);

cout << r+1 << ' ';

for (int s=0; s

cout << ArrayOfSeats[r][s] << ' ';

cout << endl;

}

}

///// MemoryCleanup Function

void MemoryCleanup (char **ArrayOfSeats, int NumberRows, int NumberSeats) {

for (int r=0; r

delete [] ArrayOfSeats[r];

delete [] ArrayOfSeats;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!