A cinema has created a booking system for their main theatre which consists of 48 seats, organised in 6 rows of 8 seats.
To store information as to whether a seat is booked or available, the program uses a 2-dimensional array (in python a list of lists). Each cell of the array contains the value 1 if the seat is booked or 0 if it is empty:
The following code is used to check whether a specific seat (identified by its row and column number) is already booked or not:
Challenge #1: Booking Options
Add a menu system to this code with 4 otpions:
- Option 1: Book a seat by row/column
- Option 2: Book a seat close to the front
- Option 3: Book a seat close to the back
- Option X: Exit
Option 1:
Let the user enter a row and column number. If the seat is available, book it by changing the corresponding value in the array to a 1. If it’s not available carry on asking for a row and column number until a free seat is found.
Option 2:
If the user chooses this option the program should automatically book the first seat available starting from the front row (row 0) from the left (column 0), and scanning each seat one by one until a free seat is found. The program should inform the user which seat (row/column) has been booked.
Option 3:
If the user chooses this option the program should automatically book the first seat available starting from the back row (row 5) from the right (column 7), and scanning each seat one by one until a free seat is found. The program should inform the user which seat (row/column) has been booked.
Challenge #2: Saving Bookings in a CSV file
Create a CSV file containing the following data:
0,1,1,0,0,1,0,1
1,0,0,1,0,1,1,0
0,1,1,1,0,0,0,1
0,0,1,1,0,1,0,0
1,0,1,1,0,0,1,1
- When the program starts, the seats array should be initialised by reading the content of the CSV file.
- When the user exit the program (option X), the content of the CSV file should be replaced with the content of the seats array.
To complete this challenge you will need to read more about how to read through a CSV file.
Challenge #3: Resetting the Array
Add an extra menu option (option 4). If this option is chosen, the seats array should automatically be reset so that all seats are reset to 0.
Challenge #4: Improvements
Can you think of any other features that could be useful to improve this cinema booking system? This could include:
- A login screen so that only authorised staff can access the booking system,
- An option to cancel a booking,
- A message to inform the end-user of how many seats are left,
- A message to inform the end-user when the theatre is full (all the seats have been booked),
- Input validation (e.g. row number between 0 and 5, column number between 0 and 7),
- Multiple bookings where the computer can identify if the user wants to book several (e.g. 2 or 3) consecutive seats on the same row,
- etc.
Solution...
The solution for this challenge is available to full members!Find out how to become a member:
➤ Members' Area