Question: 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.
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. Your program must prompt the user to enter the following information: ticket type (first class, business class, or economy class) and desired seat. Your program will prompt for an input file, and you will populate a 2D char array which holds a grid of the current seating arrangements, an X means that seat is taken and an * means the seat is vacant. You will read the user input and attempt to insert them into their desired location (as long as that indices are not out of bounds, no input failure, or if valid based on the ticket type).
takenseats.txt File contains:
* * X * X X * X * X * X * * X X * X X * X * X X * X * X * * * X * * * X X * * * X X * X * X X * X * X X * X * X * X X X * * X * X * * * X * X * * * * * X *
Must use following functions
void readSeatArrangement(ifstream&, char[][COLS]) - this function takes in an input filestream variable with the 2D char array and inserts the characters from the file into the array void outputSeatingArrangement(char[][COLS]) - this function will output the 2D grid with row and column indices void makeSeatReservation(int, int, char[][COLS]) - this function takes in the range of rows that user is allowed to book, for example if in main the ticket type is first class, then only rows 0 and 1 can be booked and therefore 0 and 1 are assigned to the two integer parameters, the function will prompt the user for a row index (int) and column index (char) and map it to a location in the 2D array, and if it is a legal position then check if contains an X or *, if it contains an * then replace that element with an X, if it contains an X then output that the location is taken and return out of the function, if the input is invalid then re-prompt until valid input is read (no input failure, and within range based on the two integer values passed in), so for example in main, if the user enters first class for ticket type then makeSeatReservation(0, 1, seatArrangement) is called, if the user enters business class then makeSeatReservation(2, 6, seatArrangement) is called an so on (seatArrangement is the 2D char array) bool isFull(char[][COLS]) - returns true if the plane is full (all elements contain X) and false otherwise
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
