Question 1[14 marks]
A cinema lets people book seats online.
The Lumen is a small cinema with one screen of 8 rows, each of 12 seats. It wants an online system that lets customers book seats for its films.
(a) Outline how decomposition could be applied to the design of this booking system. Name two sub-problems in your answer. [3]
(b) The part of the system that lets customers pick seats stores each row as a list of 0s and 1s, where 0 is a free seat and 1 is a booked seat. Identify one detail of the real cinema or its customers that this leaves out, and outline why leaving it out helps. [2]
[5]
Complete the trace table for this Java code. The Lumen cinema stores one row of seats as an array: 0 is a free seat and 1 is a booked seat. This code goes along the row from seat 0. A cell stays empty for any variable a line leaves unchanged. Then answer the question below the table. [4]
int[] row = {1, 0, 0, 1, 0};
int free = 0;
int first = -1;
for (int i = 0; i < row.length; i++) {
if (row[i] == 0) {
free = free + 1;
if (first == -1) {
first = i;
}
}
}
Why does first start at -1 and not at 0?
The Lumen cinema's booking system stores one row of seats as a list (an array in Java) of whole numbers: 0 is a free seat and 1 is a booked seat. Seat positions start at 0. A group wants to sit together. Write a function that returns the position of the first seat of the first block of n free seats next to each other.
The design team wrote this plan for it:
RUN = 0
loop through the row from position 0
if the seat is free, add 1 to RUN
otherwise set RUN back to 0
if RUN equals n, return the position
of the first seat of this block
return -1
- A block is
nfree seats in positions next to each other. If there is more than one such block, return the position of the first seat of the one that comes first (the lowest position). - If the row has no block of
nfree seats, return-1. - A block may reach the last seat of the row.
nis a whole number from 1 to 30. The row holds only 0s and 1s, has at most 30 seats, and can be empty.
Only the number your function returns is checked.
def first_block(row: list[int], n: int) -> int
public static int firstBlock(int[] row, int n)
Write it as in the exam, then run the testsPractise it with the Run button
[5]