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....

Assessment: Computer Science 4CP0 | Paper 2 Mock 01 | Written Paper 2 Subject: Computer Science - 4CP0

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.

Hourrainfall (mm)
10.0
25.0
35.1
412.4
51.8
68.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]

Answer Details

(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 IF

The 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.

Download The App On Google Playstore

Everything you need to excel in your exams

Green Bridge CBT Mobile App
Personalized AI Learning Chat Assistant
200,000+ Exam Questions Across IGCSE, JAMB, WAEC & NECO
Over 3,900 Lesson Notes
Offline Support - Learn Anytime, Anywhere
Green Bridge Timetable
Literature Summaries & Potential Questions
Track Your Performance & Progress
In-depth Explanations for Comprehensive Learning