An automated smart irrigation system uses the subroutines shown in Figure 1 to process sensor readings.
Figure 1
SUBROUTINE needsWatering(moistureLevel)
IF moistureLevel < 35 THEN
RETURN True
ELSE
RETURN False
ENDIF
ENDSUBROUTINE
SUBROUTINE calculateDeficit(moistureLevel, temperature)
adjusted ← moistureLevel - (temperature * 0.15)
IF adjusted < 0 THEN
adjusted ← 0
ENDIF
RETURN adjusted
ENDSUBROUTINE
SUBROUTINE monitorSensor(moistureLevel, temperature)
currentLevel ← calculateDeficit(moistureLevel, temperature)
OUTPUT currentLevel
IF needsWatering(currentLevel) = True THEN
OUTPUT "Activate irrigation"
ELSE
OUTPUT "Irrigation idle"
ENDIF
ENDSUBROUTINE
Describe how the programmer has used a structured programming approach in Figure 1.
131 exam-style questions on AQA GCSE Computer Science Structured programming and subroutines (procedures and functions). Each one has a worked solution and a mark scheme showing where the marks go.