The shape of the lesson
By the end of the lesson, learners can
- Top down, step by step: A car park charges drivers when they leave.
- From outline to pseudocode: When every step in Fig. 1 is refined fully, each one becomes a line or two of 9618 pseudocode.
- Logic statements: Step 2.2 is a logic statement: "free if the driver has a blue badge OR has parked for 2 hours or fewer".
- Level 1: a few steps that outline the whole solution.
- Refine: replace each step with more detailed steps, numbered 1.1, 1.2, 1.1.1 ...
- Stop: when every step can be written directly as code.
- Logic statements: complete comparisons joined by AND, OR, NOT, with brackets.
One picture every idea returns to
Stepwise refinement is the process of breaking each step of an algorithm into smaller, more detailed steps, level by level, until every step is detailed enough to be written directly as program code. The levels are often numbered 1, 1.1, 1.1.1. Parts of the refined algorithm are defined with logic statements: conditions joined by AND, OR and NOT that evaluate to TRUE or FALSE, used in IF statements and loops. Use brackets to make the order of evaluation clear.
Forty-five minutes, phase by phase
| Time | Phase | What happens in the room | Grouping |
|---|---|---|---|
| 0 to 5 min | Hook: predict | Open with the question in the title, Add detail, one level at a time.. Nobody writes a complete program straight from a one-line problem statement. Put the figure on the board: it is the one picture every idea in the lesson returns to. | Whole class, then pairs |
| 5 to 13 min | Teach and check: Top down, step by step | A car park charges drivers when they leave. Your turn: Step 2.1 in Fig. 1 says "hours, rounded up". Is that detailed enough to program? If not, refine it. | Whole class, then pairs |
| 13 to 21 min | Teach and check: From outline to pseudocode | When every step in Fig. 1 is refined fully, each one becomes a line or two of 9618 pseudocode. Model the worked example Test the refined algorithm on the board, one line at a time. Your turn: What is the charge for 245 minutes with no blue badge? | Pairs |
| 21 to 30 min | Teach and check: Logic statements | Step 2.2 is a logic statement: "free if the driver has a blue badge OR has parked for 2 hours or fewer". Project tab 3 of the lab (Logic statements in a range check) and let a student drive it while the class predicts. Model the worked example Brackets change the meaning on the board, one line at a time. Your turn: Write a logic statement that is TRUE when Mark is a valid percentage, a whole number from 0 to 100 inclusive. | Cooperative Concept Mapping |
| 30 to 36 min | Check | The four Stage 1 questions from the student lesson, answered on mini whiteboards or by show of fingers. Re-teach the one most get wrong. | Individual, then whole class |
| 36 to 43 min | Plenary | The exam-style questions from Stage 2, one at a time: thirty seconds alone, then a random call. The feedback lines in the key give the examiner's wording. | Individual, random call |
| 43 to 45 min | Exit and homework | Set the worksheet below (6 questions, 16 marks). Learners self-assess against the objectives before they leave. | Individual |
Protect the parts that carry the learning
The sequence carries about fifty minutes of material, so the lab is driven by one student while the class predicts rather than explored freely. Times are a guide.
Protected: the check at 30 minutes. It is the only individual read on whether the key idea landed, and it is not cut.
Cut first if the build overruns: the last check in Logic statements, never the check or the plenary.
In a 60 minute block: run worksheet questions 1 to 3 in class as a Rally Coach set and model both the hardest worked example and its check live.
Cooperative Concept Mapping
Teams receive the key terms on cards and arrange them on a large sheet, drawing and labelling the links. Compare maps between teams before showing the model map.
The full structure, with its variations and the other twelve, is on the cooperative-learning page.
What to head off, and how
| Trap learners fall into | Teaching move that pre-empts it |
|---|---|
| A refined step such as "work out the charge" earns no credit at the lowest level. | Each final step must say exactly what is done, with the values or the calculation, so that it could be coded without further decisions. |
| Adding 59 before DIV 60 rounds up to whole hours: 121 minutes gives 3 hours but 120 minutes gives 2. | Writing Minutes DIV 60 would round down and undercharge. |
| Each side of AND or OR must be a complete comparison. | Mark >= 0 AND <= 100 is not valid; write Mark >= 0 AND Mark <= 100. |
Stepwise refinement: worksheet
6 questions, 16 marks. Written in the style of the papers; no past paper question is reproduced.
Describe the process of stepwise refinement.
A program must "check a password". A valid password is at least 8 characters long and is not the same as the username. Refine the step check the password into detailed steps.
Write a logic statement that is TRUE when the integer variable Day holds a valid day of the month for April (1 to 30 inclusive).
Using the car park pseudocode in this lesson, state the value of Charge output for: (a) 61 minutes, no badge; (b) 400 minutes, no badge; (c) 650 minutes, no badge.
A shop gives a discount if a customer is a member and spends over $50, or if it is their birthday. A programmer writes IsMember AND (Spend > 50 OR IsBirthday). Explain why this is wrong and give a correct statement.
Give two benefits of using stepwise refinement when designing an algorithm.
Answer key and marking notes
- The algorithm is first written as a few high-level steps; each step is broken down into smaller, more detailed steps.
- This is repeated (level by level) until each step is detailed enough to be programmed.
- Input the username and the password.
- Find the length of the password (LENGTH).
- Check the length is at least 8 AND the password is not equal to the username.
- If both are true output an accepted message, otherwise output a rejected message (and ask again).
Day >= 1ANDDay <= 30.- Both comparisons complete and joined with AND (accept
Day > 0 AND Day < 31).
- (a) (61 + 59) DIV 60 = 2 hours, so 0.0.
- (b) 459 DIV 60 = 7 hours; (7 − 2) × 1.50 = 7.50.
- (c) 709 DIV 60 = 11 hours; 9 × 1.50 = 13.50, more than 12.00, so 12.00.
- It only gives a birthday discount to members, but the rule gives it to anyone on their birthday.
- Example: a non-member on their birthday gives FALSE AND (... OR TRUE) = FALSE.
- Correct:
(IsMember AND Spend > 50) OR IsBirthday.
- A large problem is tackled in small, manageable steps, so it is easier to understand and design.
- The final steps convert directly into code / errors are easier to find; parts can be shared between programmers or turned into modules.
6 multiple-choice questions on this lesson
From the topic question bank. Assign them in the app for a marked score in your gradebook, or run the topic as a class game.
Which statement describes stepwise refinement?
- AEach step of an algorithm is broken into more detailed steps, level by level, until it can be programmed
- BDetails that are not relevant are removed so that a simpler model of the problem remains
- CEach module of a finished program is tested on its own before being joined to the others
- DAn algorithm is rewritten as a flowchart so that the flow of control can be seen
A car park uses this refined algorithm. A driver without a blue badge parks for 185 minutes. What is the charge?
Hours ← (Minutes + 59) DIV 60
IF BlueBadge = TRUE OR Hours <= 2 THEN
Charge ← 0.0
ELSE
Charge ← (Hours - 2) * 1.50
IF Charge > 12.00 THEN
Charge ← 12.00
ENDIF
ENDIF- A$3.00
- B$1.50
- C$4.50
- D$6.00
Which logic statement is TRUE only when Age is from 13 to 19 inclusive?
- A
Age >= 13 AND Age <= 19 - B
Age > 13 AND Age < 19 - C
Age >= 13 OR Age <= 19 - D
Age <= 13 AND Age >= 19
When should a designer stop refining a step of an algorithm?
- AWhen the step is precise enough to be written directly as program code
- BWhen the algorithm has been refined to exactly three levels
- CWhen the step no longer contains any variables
- DWhen every step has been given its own procedure
A rule is written as this logic statement. For which person is CanVote TRUE?
CanVote ← Age >= 18 AND (IsCitizen OR IsResident) AND NOT IsBanned
- AAge 18, not a citizen, a resident, not banned
- BAge 17, a citizen, not a resident, not banned
- CAge 30, a citizen, not a resident, banned
- DAge 25, not a citizen, not a resident, not banned
A step "convert Minutes to whole hours, rounding any part of an hour up" is refined to one expression. Minutes is a positive integer. Which expression is correct for every value of Minutes?
- A
(Minutes + 59) DIV 60 - B
Minutes DIV 60 + 1 - C
Minutes DIV 60 - D
(Minutes + 30) DIV 60
Quiz key
Stepwise refinement is top-down design: each level adds detail to the steps of the level above until every step can be coded directly. Removing irrelevant detail is abstraction, testing modules separately is unit testing, and converting to a flowchart is just another way of documenting the algorithm.
Hours = (185 + 59) DIV 60 = 244 DIV 60 = 4. That is more than 2, so Charge = (4 − 2) × 1.50 = 3.00. $1.50 comes from 185 DIV 60 = 3 (rounding down), $4.50 rounds down and forgets to subtract the 2 free hours, and $6.00 rounds up correctly but also forgets the free hours.
AND requires both comparisons to be TRUE, and >= and <= include 13 and 19. Strict > and < leave out 13 and 19. With OR, every whole number satisfies at least one comparison, so the statement is always TRUE. The last option can never be TRUE, as no age is both 13 or less and 19 or more.
Refinement continues until each step can be coded without any further decisions. There is no required number of levels, steps can still use variables, and not every step becomes a procedure: many end up as one or two lines of code.
For the 18-year-old resident: 18 >= 18 is TRUE, (FALSE OR TRUE) is TRUE and NOT FALSE is TRUE, so CanVote is TRUE. The 17-year-old fails the age test, the banned citizen fails NOT IsBanned, and the 25-year-old who is neither citizen nor resident makes the bracket FALSE.
(Minutes + 59) DIV 60 gives 2 for 120 and 3 for 121, rounding up only when there is a part hour. Minutes DIV 60 + 1 gives 3 for exactly 120 minutes, overcharging on whole hours. Minutes DIV 60 always rounds down (121 gives 2), and adding 30 rounds to the nearest hour, so 121 also gives 2.
What to project
The student lesson embeds these tabs. Open them full screen on the projector; every slider has a drag handle on the stage.
Slides for this lesson
A projectable deck for every pack is on the way. Until then, present the student lesson full screen: its sections, figure and lab tabs follow the same order as the plan above.