Multiple choiceQuestion 1 · Recall
Loading…
By the end you can apply stepwise refinement (top-down design) to decompose a problem into a hierarchy of modules, and write correct logic statements using AND, OR, NOT for algorithm conditions.
Stepwise refinement is the process of starting with a high-level description and repeatedly breaking each step into more detailed sub-steps until each is simple enough to code directly.
Process:
Benefits:
Worked example: Stepwise refinement - Calculate and print class average
Read marks for 30 students, compute average, print result.
Conditions in IF, WHILE, REPEAT use logic statements with:
Truth tables:
| A | B | A AND B | A OR B | NOT A |
|---|---|---|---|---|
| F | F | F | F | T |
| F | T | F | T | T |
| T | F | F | T | F |
| T | T | T | T | F |
Precedence: NOT > AND > OR (like arithmetic: NOT = unary -, AND = *, OR = +)
Use parentheses to override: (A OR B) AND C
In Cambridge pseudocode:
AND, OR, NOT as keywordsIF (mark >= 40) AND (mark <= 100) THEN ...Worked example: Logic statements in conditions
Valid mark: between 0 and 100 inclusive. Pass: mark ≥ 50 AND attendance ≥ 75%.
When refining a condition like "valid input", you decompose the logic:
High level: IF inputIsValid THEN process ELSE error ENDIF
Refined:
inputIsValid ← (length > 0) AND (allCharsAreDigits) AND (value ≤ MAX)
Each sub-condition can be a function:
checkLength()checkDigits()checkRange()This is stepwise refinement applied to conditions — not just actions.