
Ethan O.
asked 01/30/20Please!!!! help me write this program (Do not hold the auditorium in memory. Utilize random file access to view and modify the auditorium)
Adult - $10
Child - $5
Senior - $7.50
Sample Theatre
Do not hold the auditorium in memory
- Utilize random file access to view and modify the auditorium
Input validation
Parameter: input string
Return: Boolean
- Parse string character by character
- If invalid character, return false
- Return True
Best Available
Parameter: row, total quantity
Return: starting seat
- Open file
- For 1 to N-x+1 (N = number seat in a row, X = total number of tickets)
- For 1 to total quantity
- Read character
- If character != period
- Break
- If loop ends and all seats checked are empty
- calculate distance
- (outer loop counter + (total quantity-1)/2 - (N+1)/2
- Keep smallest distance and starting seat number
- Close file
- Return starting seat number
- -1 if no best seats available
Display Auditorium
Parameter: none
Return: nothing
- Open file
- display column header
- While not EOF
- Read lines
- Display row number
- Display line
- change character to #
- close file
Reserve Seats
Parameter: row, seat, adult quantity, senior quantity, child quantity
Return: nothing
- Open file
- Move file pointer to proper row
- Move file pointer to proper character (seat)
- For each ticket type
- For 1 to quantity
- Write appropriate letter to file
- Close file
Check Availability
Parameter: row, seat, total quantity
Return: Boolean
- Open file
- Move file pointer to proper row
- Move file pointer to proper character (seat)
- For 1 to quantity
- Read character
- If character is not a period
- Close file
- Return false
- Close file
- Return true
Display Report
Parameter: none
Returns: nothing
- Open file
- While not EOF
- Read character
- Increment appropriate counter on character read
- A = adult, S = senior, C = child, period = empty
- Print report
- Total seats
- Total sold
- Adult Sold
- Child sold
- Senior sold
- Total sales
- Close file
Main
- Loop (do...while not exit)
- Print main menu
- Get user input
- If user does not want to exit
- Display auditorium
- Ask user for row, seat and quantities (adult, child, senior)
- Validate input for each input
- Loop if not valid
- Check if seats are available
- If available reserve seats
- If seats not available
- Find best available seats
- Ask user to reserve best available ( if found)
- If user accepts
- Reserve seats
- Print Report
1 Expert Answer

Patrick B. answered 02/08/20
Math and computer tutor/teacher
I wish to discuss the design of this program in greater detail. There is much more that needs to be addressed.
For example:
(1) is there more than 1 auditorium ( file) involved???
(1) How are the reserved seats assigned the values {A,S,C}
(2) are the prices stored in a file, as the each auditorium can charge difference prices
(3) each auditorium has a different layout ( # of rows, # of seats per row)
(4) sales statistics for each auditorium kept in the same file or different file
(5) how are the seats selections actually made? you can search each row for the
appropriate number of empty seats and then report that row as available
(6) more than one report can be generated: sales and seats
Availability can be checked with the strstr function as shown in the program below. It creates an
auditorium file 5 rows x 20 seats per row, then reserves 10 seats in row 3 seats 7-16.
Finally it looks for available rows of 20 seats, which shall be rows #1,2,4,5.
----------------------------------------------------------------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
//creates a file with empty auditorium: 5 rows x 20 seats per row = 100
FILE * fptr = fopen("datafile.dat","wb");
char outbuff[100];
memset(outbuff,'0',100);
fwrite(outbuff,sizeof(char),100,fptr);
fclose(fptr);
//populates a row of 10 seats, row #3 seats 7
fptr = fopen("datafile.dat","rb+");
int rowNum=2;
int seatNum=7;
sprintf(outbuff,"SACSCAASCA");
fseek(fptr,rowNum*20+seatNum,SEEK_SET);
fwrite(outbuff,sizeof(char),10,fptr);
fclose(fptr);
char buff[20];
fptr = fopen("datafile.dat","rb+");
int iLoop;
//looks for rows that can hold 20 guests: rows #1,2,4,5
for (iLoop=0; iLoop<5; iLoop++)
{
fread(buff,sizeof(char),20,fptr);
if (strstr(buff,"00000000000000000000")!=NULL)
{
printf(" seats available at row # %d \n",(iLoop+1));
}
}
fclose(fptr);
}
Still looking for help? Get the right answer, fast.
Get a free answer to a quick problem.
Most questions answered within 4 hours.
OR
Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.
Patrick B.
I would keep 3 files: (1) the main binary file that holds the auditorium data , a 2 x 2 array of characters O,S,A,C (2) an index file which contains the prices, # of rows,and # of seats per row (3) a file which contains the sales statistics; the files are kept in-sync using a primary key called the AUDITORIUM ID #; THIS is the proper database design, and the requirements of this assignment are asking for it02/08/20