Question 1 Report
A cinema stores seat booking data in a 2D array. Each element contains TRUE (booked) or FALSE (available).
DECLARE Seats : ARRAY[1:4, 1:6] OF BOOLEAN
The current bookings are shown below (T = booked, F = available):
| Seat 1 | Seat 2 | Seat 3 | Seat 4 | Seat 5 | Seat 6 | |
|---|---|---|---|---|---|---|
| Row 1 | T | T | F | F | T | T |
| Row 2 | F | T | T | T | F | F |
| Row 3 | T | T | T | T | T | T |
| Row 4 | F | F | T | F | F | T |
(a) State the value of Seats[2, 4]. [1]
(b) Write pseudocode to count and output the total number of available (FALSE) seats. [3]
(c) Write pseudocode to count and output the number of available seats in each row. [2]
(a) Seats[2, 4] = TRUE [1] (Row 2, Seat 4 is booked).
(b) Pseudocode to count total available seats: [3]
DECLARE Available : INTEGER
Available <- 0
FOR Row <- 1 TO 4
FOR Seat <- 1 TO 6
IF Seats[Row, Seat] = FALSE
THEN
Available <- Available + 1
ENDIF
NEXT Seat
NEXT Row
OUTPUT "Total available seats: ", Available[1] for nested loops covering all rows and seats, [1] for checking for FALSE (available), [1] for counting and output.
Counting available (F) seats per row: Row 1 has 2 (seats 3, 4), Row 2 has 3 (seats 1, 5, 6), Row 3 has 0 (fully booked), Row 4 has 4 (seats 1, 2, 4, 5). Total: 2 + 3 + 0 + 4 = 9 available seats.
(c) Pseudocode to count available seats per row: [2]
FOR Row <- 1 TO 4
DECLARE RowCount : INTEGER
RowCount <- 0
FOR Seat <- 1 TO 6
IF Seats[Row, Seat] = FALSE
THEN
RowCount <- RowCount + 1
ENDIF
NEXT Seat
OUTPUT "Row ", Row, " available: ", RowCount
NEXT RowThe key difference from part (b) is that RowCount is reset to 0 at the start of each row, so each row gets its own count. The OUTPUT is inside the outer loop (but after the inner loop), producing one line per row. Expected output: Row 1: 2, Row 2: 3, Row 3: 0, Row 4: 4.
Everything you need to excel in your exams