Question 1 Report
A coastal weather station writes hourly rainfall readings to a file. The code editor must process eight readings and count how many are greater than 5.0 mm. Table 1 shows the first six values from one day. The variable wetHours starts at 0. The program uses a FOR loop because the number of readings is known before the program starts. A trainee has confused the loop control variable with the rainfall data variable.
| Hour | rainfall (mm) |
|---|---|
| 1 | 0.0 |
| 2 | 5.0 |
| 3 | 5.1 |
| 4 | 12.4 |
| 5 | 1.8 |
| 6 | 8.0 |
(a) Identify the construct used when a program repeats a known number of times. [1]
(b) Complete the loop header: FOR hour ______ 1 TO 8 [3]
(c) Use Table 1 to write pseudocode that increases wetHours for each reading greater than 5.0 mm. [3]
(a) A FOR loop, also called a count-controlled loop, repeats a known number of times. [1]
(b) The loop control variable is assigned its starting value:
FOR hour = 1 TO 8
The equals sign gains [1]; the complete header is accepted for [2]. [3]
(c) The comparison must use the rainfall value, not the hour number. Values equal to 5.0 mm do not count because the requirement is “greater than 5.0 mm”:
IF rainfall > 5.0 THEN
wetHours = wetHours + 1
END IFThe condition [1], count increment [1], and valid selection syntax [1] give [3]. From the values shown, 5.1, 12.4 and 8.0 mm meet this condition.
Everything you need to excel in your exams