An algorithm is designed for a greenhouse monitoring system to log environment sensor readings:
1 SET sensorList TO ["Temp", "Humid", "Light", "CO2"]
2 SET activeFlags TO [True, True, True, False]
3 SET logCount TO 0
4 SET mode TO "Standard" # System operation mode
5 SET alertsEnabled TO True
6
7 FUNCTION recordReading(sensorNum, val)
8 BEGIN
9 DECLARE mode : BOOLEAN
10 SET mode TO False
11 IF (activeFlags[sensorNum] == True) THEN
12 SEND "Logging " & sensorList[sensorNum] & " value: " & val TO FILE
13 SET logCount TO logCount + 1
14 SET mode TO True
15 END IF
16 RETURN mode
17 END FUNCTION
Compare the scope and memory use of the variable mode referred to on line 4 of the algorithm, with the variable mode referred to on line 10.
Practise Edexcel GCSE Computer Science Subprograms with exam-style questions for GCSE Computer Science. 29 questions covering Built-in and user-devised subprograms, Functions versus procedures, and Global and local variables, 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.