The following pseudocode uses a subprogram to log and display temperature data for an automated greenhouse ventilation system.
1 SET statusFlag TO "ALERT: UNINITIALISED"
2
3 PROCEDURE monitorTemperature ( sensorTemp, targetTemp )
4 BEGIN PROCEDURE
5 SET statusFlag TO "SYSTEM: MONITORING"
6
7 # calculate temp difference
8 SET tempDiff TO sensorTemp - targetTemp
9
10 # calculate fan power percentage
11 SET fanPower TO tempDiff * 8.5
12
13 # output status and control parameters
14 SEND statusFlag TO DISPLAY
15 SEND "Current Temp: " & sensorTemp TO DISPLAY
16 SEND "Difference: " & tempDiff TO DISPLAY
17 SEND "Fan Speed (%): " & fanPower TO DISPLAY
18 END PROCEDURE
19
20 SEND statusFlag TO DISPLAY
21 SEND "Enter current sensor temperature:" TO DISPLAY
22 RECEIVE currentTemp FROM (REAL) KEYBOARD
23 SEND "Enter target temperature:" TO DISPLAY
24 RECEIVE targetTemp FROM (REAL) KEYBOARD
25 CALL monitorTemperature(currentTemp, targetTemp)
Explain how the correct value for the variable statusFlag is chosen on line 14.
29 exam-style questions on Edexcel GCSE Computer Science Subprograms, covering Built-in and user-devised subprograms, Functions versus procedures, and Global and local variables. Each one has a worked solution and a mark scheme showing where the marks go.