Uploaded by Terry Massy

CS homework

advertisement
Write a program that meets the following requirements:
• counts and outputs the number of seats already booked for the evening
• allows the user to input the number of seats required
• validates the input
• checks if enough seats are available:
– if they are available
○ changes the status of the seats
○ outputs the row number and seat number for each seat booked
– if they are not available:
○ outputs a message giving the number of seats left or ‘House full’ if the theatre is fully
booked.
ANS) In order for the program to count and output the number of seats already booked, a nested loop
has to be used. ie, any two integer variables, such as rows and columns, will be used to search through
each index of the array Evening, and a REPEAT…UNTIL loop has to be used in order to check whether
the index value of the array is TRUE or FALSE. If the value is FALSE, the loop will terminate. If the value is
TRUE, another variable, Booked_Seats, will be incremented by 1. The next thing the program requires is
to allow the user to input the number of seats they need, and validating the input. This can be done by
first taking the user input by a simple INPUT command, storing the INPUT value into the variable
Seats_Required, and then validating user input by using another REPEAT…UNTIL loop to see if the user
input is with the range 1 to 4 (inclusive). Then we have to check if enough seats are available for booking
by the user. To do this, we need to first calculate and store the total number of seats in the variable,
Total_Seats, 10 x 20, then we can calculate the number of seats that are available, Total_Seats –
(Booked_Seats + Seats_Required). With this step, we will also be changing the current value in
Booked_Seats by adding Seats_Required to it. If the number is greater than or equal to 0, the seats are
available. Thus, we use another loop to change the value of the FALSE indexes in the array by the given
variable, Seats_Required. I.e, if 3 seats are required by the user, the loop will first search through each
index of the array till it finds an index with FALSE in it, and then change the following two indexes to
TRUE. However, if Total_Seats – (Booked_Seats + Seats_Required) is smaller than 0, then instead a
message will be OUTPUT, “House Full”.
Download