An automated aquarium life-support system uses the following algorithm to monitor water parameters and control actuators, but it does not make efficient use of selection structures.
1 WHILE (monitorActive = True) DO
2
3 RECEIVE phSensor FROM PH_SENSOR
4 IF (phSensor > 8.2) THEN
5 SET acidDoseStatus TO "On"
6 END IF
7
8 RECEIVE salinitySensor FROM SALINITY_SENSOR
9 IF (salinitySensor < 32.0) THEN
10 SET saltDoseStatus TO "On"
11 END IF
12
13 RECEIVE dissolvedOxygenSensor FROM DO_SENSOR
14 IF (dissolvedOxygenSensor < 6.5) THEN
15 SET aeratorStatus TO "On"
16 END IF
17
18 IF (phSensor <= 8.2) THEN
19 SET acidDoseStatus TO "Off"
20 END IF
21
22 IF (salinitySensor >= 32.0) THEN
23 SET saltDoseStatus TO "Off"
24 END IF
25
26 IF (dissolvedOxygenSensor >= 6.5) THEN
27 SET aeratorStatus TO "Off"
28 END IF
29
30 END WHILE
Write replacement code to control the aquarium aerator (aeratorStatus) that would improve the efficiency of this algorithm.
Practise Edexcel GCSE Computer Science Algorithms with exam-style questions for GCSE Computer Science. 100 questions covering Constructs for solving problems, Variables, constants and data structures, Arithmetic, relational and logical operators, Tracing algorithm output with trace tables, Types of error and correcting logic errors, Standard algorithms (sorts and searches), and Evaluating algorithm fitness and efficiency, matched to the Edexcel GCSE Computer Science (1CP2) specification and written in Paper 1 and Paper 2 style. Every question includes a full worked solution and mark scheme, so you can see where marks are awarded rather than just whether you got the answer right.