Question 1 Report
A museum kiosk lets visitors search a file of artefact codes. The code editor uses a count-controlled loop to examine the first five records. Table 1 shows the artefact data currently in the program. The variable found starts with the value 0. Each time the program reads the word bronze in the material field, it adds 1 to found. The programmer wants to check that the loop, comparison and total are correct before uploading the program.
| Record number | Artefact code | Material |
|---|---|---|
| 1 | M14 | bronze |
| 2 | K08 | glass |
| 3 | R31 | bronze |
| 4 | A19 | stone |
| 5 | B06 | bronze |
(a) Identify the programming construct used to repeat an instruction exactly five times. [2]
(b) Write the assignment statement that increases found by 1. [2]
(c) Use Table 1 to state the final value displayed for found. [2]
(a) A FOR loop [1] is used for this count-controlled iteration [1], because the instruction is repeated exactly five times. [2]
(b) A running total is increased by assigning its old value plus one back to itself:
found = found + 1
[2]
(c) Records 1, 3 and 5 have material bronze. Starting at 0, the total increases three times, so the final value of found is 3. [2]
Everything you need to excel in your exams