A bus has 28 seats, arranged in 7 rows and 4 columns: This seating arrangement is mapped,
Question:
A bus has 28 seats, arranged in 7 rows and 4 columns:
This seating arrangement is mapped, row-wise, to a 1D-array of size 28:
0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
| | | | | | | | | | | | | | | | | | | | | | | | | | | |
Implement a well-structured C program to enable a user to make and cancel seat reservations for the bus. The program uses a text-file seats.txt to store the reservation information: 0 indicates that a seat is not reserved, and 1 indicates that a seat is reserved. Originally all seats are not reserved:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 |
Your program starts by initializing a 1D-array with the current contents of the seats.txt file. It must then display the following menu:
1. Display number of available seats.
2. Display seat status for all seats.
3. Reserve seat(s).
4. Delete reservation(s).
5. Exit.
Please select your choice:
Your program must loop as long as option 5 has not been selected. It must display an appropriate error message if an invalid choice is entered. After executing each of the options 1 to 4, your program must pause and display the message: “Press Enter key to continue . . .”. Your program must display the above menu after pressing the Enter keyThe options must have the following behaviors:
1: Display number of available seats
It displays the current number of available seats. It then waits for the Enter key to be pressed before returning control to the main menu.
If four seats are reserved, for example, hen the output is:
2: Display seat status for all seats
It displays the status of each seat. The option then waits for the Enter key to be pressed before returning control to the main menu.
3: Reserve seat(s)
It displays the status of each seat.
It displays the number of available seats.
If there are no available seats, the message: “Sorry, there are no available seats.” is displayed:
If there is one or more available seats, it prompts the user for and reads the number of required reservations. If the number of required reservations is more than the number of available seats, the message: “Error: Insufficient available seats.” is displayed:
If the number of required reservations is zero or negative, the error message: “Error: Invalid number of seats.” Is displayed:
If the required number of reservations is valid and sufficient, the program prompts for and reads the seat number
and checks that the seat number is valid and does the reservation. If the seat number is not valid or already reserved, it displays a message and asks again for the seat until all seats are reserved.
If the reservation is successful, the message: “Required seats successfully reserved” is displayed:
4 . Delete reservation(s)
It displays the available seats if any.
It prompts for and reads the number of seats whose reservations are to be deleted.
If the number of seats whose reservations are to be deleted is not valid, the error message: “Error: Invalid number of reservations to delete.” Is displayed:
If the number of seats whose reservations are to be deleted is valid, the program prompts for and reads the seat number of each seat whose reservation is to be deleted, the program prompts for the seat numbers and does the necessary validation as in reservation part.
If the deletion is successful, the message: “Required reservation(s) successfully deleted” is displayed:
Whether the update operation was done or not, control is returned to the main menu after pressing the Enter key.
5. Exit
It terminates the program and writes the updated array into the seats.txt file.
Understanding Basic Statistics
ISBN: 978-1111827021
6th edition
Authors: Charles Henry Brase, Corrinne Pellillo Brase