Note AcademyNote Academy

Computer Science · Oct / Nov 2023 · Paper 21 · Question 10

0478

As printed in the paper

The question as text

Drama students put on a performance of a play for one evening. Seats in a small theatre can be booked for this performance. The theatre has 10 rows of 20 seats. The status of the seat bookings for the evening is held in the tw Evening[] Each element contains FALSE if the seat is available and TRUE if the seat is booked. Up to and including four seats can be booked at one time. Seats are allocated in order from those available. A row or seat number cannot be requested. The array Evening[] has already been set up and some data stored. 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 bo You must use pseudocode or program code and add comments to explain how your code works. You do not need to declare any arrays or variables; you may assume that this has already been done. You do not need to initialise the data in the array Evening[] All inputs and outputs must contain suitable messages.

Read automatically from the paper; the printed page above is exact.

Show the answer and mark scheme
AO2 (maximum 9 marks)
AO3 (maximum 6 marks)

Data Structures required names shown underlined must be used as given in the scenario

2D Array or list Evening[1:10, 1:20] / Evening[0:9, 0:19]

Variables Counter, SeatCounter, NumSeats, Row, Column

Requirements (techniques)

R1 Find number of seats available for each performance and output (searching, nested iteration, output)

R2 Inputs and validates number of seats (input, iteration, and selection)

R3 Checking if seats available (selection, assignment, output with appropriate messages)

Example 15-mark answer in pseudocode

// meaningful identifier names and appropriate data structures to store the data required DECLARE Counter, SeatCounter, NumSeats, Row, Column : INTEGER

CONSTANT HouseFull = 200

CONSTANT MaxRow = 10

CONSTANT MaxColumn = 20

SeatCounter1 ← 0 // initialise seat counter for performance 1

FOR Row ← 1 TO 10

FOR Column ← 1 TO 20

IF Evening[Row, Column]

THEN

SeatCounter ← SeatCounter + 1

ENDIF

NEXT Column

NEXT Row

// validate input

OUTPUT "How many seats do you want to book? 1, 2, 3 or 4 "

INPUT NumSeats

WHILE 1 < NumSeats OR NumSeats > 4 OR NumSeats <> ROUND(NumSeats, 0)

OUTPUT "Please enter 1, 2, 3 or 4 for the number of seats "

INPUT NumSeats

ENDWHILE

IF SeatCounter + NumSeats > 200)// check for house full

THEN

OUTPUT "House full"

ELSE

IF SeatCounter + NumSeats > 200 // checks for not enough seats

THEN

OUTPUT "Only ", SeatCounter + NumSeats – 200, " seats left"

ELSE

FOR Counter ← 1 TO NumSeats // book required number of seats for performance Evening[MOD(SeatCounter + Counter, MaxColumn), DIV(SeatCounter + Counter), MaxColumn] ← TRUE

OUTPUT "Row ", MOD(SeatCounter + Counter, MaxColumn), " seat ",

DIV(SeatCounter + Counter, MaxColumn)," booked"

NEXT Counter

ENDIF

AO2:

Apply knowledge and understanding of the principles and concepts of computer science to a given context, including the analysis and design of computational or programming problems

Make a free account to save your answers and see your weak topics and ask the AI why a wrong answer is wrong.