Skip to content

Course home

Programming concepts

Programming concepts

EasyMediumHard
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
Question 12

An engineer is writing an algorithm to process and sum the daily temperature readings for five monitoring sensors, each recording four readings over a 24-hour cycle. There are 20 historical readings recorded in total.

The algorithm below contains a logic error and fails to process all 20 temperature readings.

1  sensors ← ['Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon']
2  readings ← [14.2, 15.1, 14.8, 13.9, 18.0, 18.5, 17.9, 19.1, 12.1, 11.8, 12.5, 13.0, 15.5, 16.0, 15.8, 15.2, 20.1, 21.3, 20.8, 19.9]
3  totalTemp ← 0.0
4  FOR i ← 0 TO 4
5      sensorName ← sensors[i]
6      OUTPUT 'Sensor: ', sensorName
7      FOR j ← 0 TO 2
8          OUTPUT 'Reading: ', j + 1
9          temp ← readings[i * 4 + j]
10         OUTPUT temp
11         totalTemp ← totalTemp + temp
12     ENDFOR
13 ENDFOR

How could the error in the algorithm be corrected so that all 20 temperature readings are processed?

A

Change line number 4 to: FOR i ← 0 TO 5

B

Change line number 7 to: FOR j ← 0 TO 3

C

Change line number 9 to: temp ← readings[i * 5 + j]

D

Change line number 11 to: totalTemp ← totalTemp + readings[i]

Markscheme

Programming concepts Questions

  1. GCSE
  2. /Computer Science
  3. /Programming concepts

298 exam-style questions on AQA GCSE Computer Science Programming concepts. Each one has a worked solution and a mark scheme showing where the marks go.

Question bank