Cover lesson · Computer Science · Year 8 · Intermediate

Tracing and Debugging a River Flood Warning Flowchart

DCF: Data and computational thinking → Problem-solving and modelling · LNF: Numeracy → Logical reasoning

Name: Class: Date:

Cover teacher: you need no subject knowledge

What this practises: computational thinking and logical reasoning in Computer Science. Pupils dry-run a faulty flood-warning flowchart against 8 hourly river and rainfall readings using a trace table, uncover two logic bugs (OR used instead of AND, and < used instead of >=), verify their fix including a boundary test, and write the corrected algorithm in pseudocode.

Board: open the supply teacher presentation for board slides, timers and script.

Print: this worksheet, one per pupil, and the stimulus sheet “Afon Glyn flood sensor readings and trainee flowchart”, one between two. No computers or calculators needed.

Run: 5 min starter and read stimulus · 5 min key words · 10 min Step 1, trace the faulty flowchart · 10 min Step 2, diagnose and fix the 2 bugs · 12 min Steps 3 and 4, re-trace and write pseudocode · 5 min partner check · 3 min plenary check. Total 50 minutes.

Collect: this worksheet. Quick checks: the faulty flowchart fails at 04:00 (outputs RED instead of AMBER) and 07:00 (outputs GREEN instead of AMBER); fixed Diamond D2 is level >= 3.2 AND rain >= 15; fixed Diamond D3 is level >= 2.4.

What you are doing

An automated sensor on Pont Glyn bridge measures the height of the Afon Glyn (level, in metres) and the rainfall rate (rain, in mm/hr) every hour. During last night’s storm, a trainee programmer’s flowchart triggered a false village evacuation at 04:00 and missed a real flood warning at 07:00. You will trace the faulty flowchart to prove why it failed, correct both decision diamonds, and write the fixed rules in pseudocode.

Step 1: Dry-run the trainee’s faulty flowchart

Follow the trainee’s flowchart in section 2 of the stimulus sheet exactly as it is written for all 8 hourly readings. Write Yes, No, or a dash (-) if a diamond is not reached. In the last column, use the official specification in section 1 to write what the alert should have been, then circle the two hours where the outputs do not match.

Time level (m) rain (mm/hr) D1:
level < 2.0?
D2:
level >= 3.2 OR rain >= 15?
D3:
level < 2.4?
Faulty output Expected output (spec)
01:00 1.4 2 Yes - - GREEN GREEN
02:00 1.7 5
03:00 1.9 11
04:00 2.6 18
05:00 3.3 19
06:00 3.4 16
07:00 2.8 9
08:00 1.8 3

Step 2: Diagnose and fix the two logic bugs

Complete the bug report below for Diamonds D2 and D3.

Diamond Faulty condition Why it caused a wrong alert (quote the hour and numbers) Corrected condition
Diamond D2
(Red check)
level >= 3.2 OR rain >= 15
Diamond D3
(Amber check)
level < 2.4

Step 3: Re-test with the corrected diamonds (including two boundary tests)

Trace these 5 test cases through your corrected flowchart to prove that your fix works, including two boundary tests right on the 2.0 m and 2.4 m thresholds.

Test case level (m) rain (mm/hr) D1:
level < 2.0?
Fixed D2:
level >= 3.2 AND rain >= 15?
Fixed D3:
level >= 2.4?
Fixed output
04:00 storm shower 2.6 18
06:00 peak flood 3.4 16
07:00 high river 2.8 9
Boundary test A 2.4 10
Boundary test B 2.2 10

Step 4: Write the corrected pseudocode

(a) Complete the pseudocode for the fixed Pont Glyn flood alert algorithm using IF, ELSE IF, ELSE and END IF.

INPUT level, rain

IF level < 2.0 THEN

    OUTPUT "GREEN: Normal"

ELSE IF ____________________________________________________ THEN

    OUTPUT "__________________________________________"

ELSE IF ____________________________________________________ THEN

    OUTPUT "__________________________________________"

ELSE

    OUTPUT "__________________________________________"

END IF

(b) Explain why the program must check the RED condition (level >= 3.2 AND rain >= 15) before it checks the AMBER condition (level >= 2.4).

Step by step

  1. 5 min Answer the starter question and read sections 1 and 2 of the stimulus sheet.
  2. 5 min Check the meanings of AND, OR, < and >=.
  3. 10 min Step 1: trace all 8 hourly readings through the faulty flowchart and circle the 2 failed hours.
  4. 10 min Step 2: explain both logic bugs and write the corrected diamond conditions.
  5. 12 min Steps 3 and 4: re-trace the 5 test cases and complete the corrected pseudocode and explanation.
  6. 5 min Swap with a partner to check boundary cases and tick the success criteria.
  7. 3 min Plenary: check your answers against the board.

Success criteria

If you finish early