Question 1 Report
Fig. 1 shows part of a program used to create seat labels for a small theatre. There are 3 rows and 4 seats in each row. The outer loop controls the row number and the inner loop controls the seat number. For each seat, the program displays a label such as R2-S3. A programmer has removed two words from the code and wants to check the sequence of labels before saving the source file. The diagram is a structured representation of nested iteration.
Fig. 1: nested loops for theatre-seat labels
(a) Identify the total number of labels displayed when the program is correct. [2]
(b) Write the two labels displayed immediately after R1-S4. [2]
(c) Use the code in Fig. 1 to complete a trace table for row 3 by giving the values of seat and the label displayed for all four inner-loop repetitions. [4]
(a) There are 3 rows with 4 seats each:
\[3 \times 4 = 12\]
Therefore, 12 labels are displayed [2]. The inner loop completes four times for each outer-loop row.
(b) After R1-S4, the inner loop has finished for row 1. The next two labels are R2-S1 [1] and R2-S2 [1]. [2]
(c) When row = 3, the inner loop changes seat from 1 to 4:
| seat | Label displayed |
|---|---|
| 1 | R3-S1 |
| 2 | R3-S2 |
| 3 | R3-S3 |
| 4 | R3-S4 |
Each correct seat value and matching label gains [1]. [4]
Everything you need to excel in your exams