Using the following implementation design, write a program that can be used by a small venue to manage which seats have been reserved for a performance. The venue has 15 rows of seats with 30 seats in each row. When requested, the program should display a screen that shows which seats are available and which are taken. For example, the following image shows a chart depicting each seat in a venue. Seats that are taken are represented by an * symbol, and seats that are available are represented by a # symbol.

When the program begins, it should ask the user to enter the name of a text file containing the current seating chart. The file will consist of 15 lines with 30 characters (* or #) on each line separated by spaces. The program should read the contents of the file to initialize its seating chart. You may use the following file as a seating chart for your program: venuSeating.txt.

The program should provide the following options to the user:

  • Reserve seat
  • View Seating Chart
  • Show Statistics
  • Quit Program

When the user wants to reserve a seat, the program should display the current seating chart and then prompt the user for how many seats he wants to reserve. The program will then prompt the user N times to enter the row and seat number for the seat he wants to reserve and update the seating chart.

The show statistics option displays important statistics to the user about the venue's current reservations. It should display how many seats have been reserved, how many seats are available in the entire venue and how many seats are available in each row.

When the user selects to quit the program, the program should save the current state of its seating chart in the same text file from which it originally read the seating chart from.

Input validation:

  • When reading data from the file, the program should validate that it only reads '*' and '#' characters.
  • When seats are being reserved, do not accept row or seat numbers that do not exist.
  • When someone requests a particular seat, the program should make sure that seat is available before it is reserved.

Additional Assignment Requirements and Notes

  • You must use a 2-dimensional array to store your seating chart.
  • You must decompose your program into functions and optionally files.

Sample Output

Enter reservations state file name: venuSeating.txt

1. Reserve Seats
2. View Seating Chart
3. Show Statistics
4. Quit
Choice: 1

Seats
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
Row 1 * * * # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 2 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 3 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 4 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 5 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 6 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 7 # # # # # # # # # # # # # # * # # # # # # # # # # # # # # #
Row 8 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 9 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 10 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 11 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 12 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 13 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 14 * # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 15 # # # # # # # # # # # # # # # # # # # * # # # # # # # # # *

How many seats do you want to reserve? 2
Enter row # and seat # of the seat to reserve: 3 1
Enter row # and seat # of the seat to reserve: 3 2

1. Reserve Seats
2. View Seating Chart
3. Show Statistics
4. Quit
Choice: 2

Seats
0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3
1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
Row 1 * * * # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 2 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 3 * * # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 4 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 5 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 6 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 7 # # # # # # # # # # # # # # * # # # # # # # # # # # # # # #
Row 8 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 9 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 10 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 11 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 12 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 13 # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 14 * # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
Row 15 # # # # # # # # # # # # # # # # # # # * # # # # # # # # # *

1. Reserve Seats
2. View Seating Chart
3. Show Statistics
4. Quit
Choice: 3

Total Seats Reserved: 9
Total Seats Available: 441
Number of Seats Available by row:
Row 1: 27
Row 2: 30
Row 3: 28
Row 4: 30
Row 5: 30
Row 6: 30
Row 7: 29
Row 8: 30
Row 9: 30
Row 10: 30
Row 11: 30
Row 12: 30
Row 13: 30
Row 14: 29
Row 15: 28

1. Reserve Seats
2. View Seating Chart
3. Show Statistics
4. Quit
Choice:

Design Document

Overview

This program manages the reservation of seats for a small venue's auditorium. The auditorium has 15 rows of 30 seats each.

The program presents the user the following menu options:

  • Reserve seat
  • View Seating Chart
  • Show Statistics
  • Quit Program

The program maintains the set of reserved seats within a text file between program runs. The program asks the user for the name of the text file when it is first run, it reads the data from the file, and then writes data back to the file when the user selects quit from the menu.

Structure Chart

Figure: see image.

Global Variables and Constants

Name Type Description
N_ROWS Int Constant representing the number of rows in the auditorium. Default is 15.
N_SEATS Int Constant representing the number of seats in each row of the auditorium. Default is 30.
SEAT_AVAILABLE Char Character indicating that a particular seat is available. Default is: '#'
SEAT_RESERVED Char Character indicating that a particular seat is reserved. Default is: '*'
MENU_CHOICE_RESERVE Int Constant representing "reserve seat" menu option. Default is 1.
MENU_CHOICE_DISPLAY Int Constant representing "view seating chart" menu option. Default is 2.
MENU_CHOICE_SHOW_STATS Int Constant representing "show statistics" menu option. Default is 3.
MENU_CHOICE_QUIT Int Constant representing "quit" menu option. Default is 3.

Algorithms and Calculations

None.

Detailed Design

Function main

This function manages the seat reservation for a small venue's auditorium.

Parameters

Name Type Direction (in/out) Description
None.

Pseudo Code

  • Ask the user to enter a file name containing the reservation state.
  • Open the file and load the data into a 2-dimensional array - call loadReservationState()
  • Return a non-zero status if there was a failure loading the file.
  • While the user doesn't want to quit
    • Display menu and get the user's choice, getMenuChoice()
    • Process the user's choice - call processChoice

Function loadReservationState

This function opens the specified file and reads its contents into the provided array.

Parameters

Name Type Direction (in/out) Description
stateFileName string In Name of the containing reservation state.
reservations char[][] In/Out 2-dimensional array to hold the seat reservation status

Pseudo Code

  • Open the file. If it fails, display message and return false.
  • For each element in the array
    • Read a character from the file
    • Verify that the character is # or *, if it isn't display message and exit loop
    • Store the character in the array
  • Close file

Function saveReservationState

This function opens the specified file and writes the contents of the reservations array to the file.

Parameters

Name Type Direction (in/out) Description
stateFileName string In Name of the file containing reservation state.
reservations char[][] In 2-dimensional array containing the reservation seat status

Pseudo Code

  • Open the file. If it fails, display message and return false.
  • For each row in the array
    • For each column in the array, Write the value of the element to the file
    • Write a newline character to the file
  • Close file

Function getMenuChoice

This function displays the menu and returns the user's choice - MENU_CHOICE_XXX

Parameters

Name Type Direction (in/out) Description
None.

Pseudo Code

  • Display the menu
  • Ask the user to enter a choice and return it.

Function processChoice

This function invokes the appropriate function based on the user's choice.

Parameters

Name Type Direction (in/out) Description
choice Int In User's menu choice
reservations char[][] In/out 2-dimensional array to hold the seat reservation status

Pseudo Code

  • If choice is MENU_CHOICE_RESERVE, call makeReservation()
  • If choice is MENU_CHOICE_DISPLAY, call displayReservationState()
  • If choice is MENU_CHOICE_SHOW_STATS, call calculateReservationStatistics()

Function makeReservation

This function asks the user which seat(s) he wants to reserve and updates the status of the seats in the reservations array.

Parameters

Name Type Direction (in/out) Description
reservations char[][] In/out 2-dimensional array to hold the seat reservation status

Pseudo Code

  • Display the current seating chart - call displayReservationState()
  • Ask the user how many seats he wants to reserve.
  • For each seat to be reserved
    • As the user for the row number and seat number he wants to reserve, call getSeat()
  • Return true.

Function getSeat

This function prompts the user for a row number and seat number.

Parameters

Name Type Direction (in/out) Description
row Int In/out Row number that is entered by the user.
Seat Int In/out Seat number that is entered by the user

Pseudo Code

  • While the user has not entered a valid row and seat number
    • Display the prompt.
    • Get a row and seat number from the user.
    • If there was an error or the row and/or seat number are out of range, display message and try again; otherwise, return true.

Function displayReservationState

This function displays the contents of the reservations array to the user. The output is similar to the following: see image.

Parameters

Name Type Direction (in/out) Description
reservations char[][] In 2-dimensional array to hold the seat reservation status

Pseudo Code

  • Display the heading rows.
  • For each row in the reservations array
    • Display row heading (Row #)
    • For each seat in the row, display the status of the seat.

Function calculateReservationStatistics

This function displays the following statistics about the venue's current reservations.

  • How many seats have been reserved.
  • How many seats are available in the entire venue.
  • How many seats are available in each row.

Parameters

Name Type Direction (in/out) Description
reservations char[][] In 2-dimensional array to hold the seat reservation status

Pseudo Code

  • Walk through the reservation array and collect the following information for each row:
    • # of seats reserved
    • # of seats available
  • Display results
Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.