The shape of the lesson
By the end of the lesson, learners can
- Declare, initialise, assign: Exam questions give you a design as a program flowchart or as structured English and ask for pseudocode.
- Operators and expressions: An expression is anything that evaluates to a single value.
- Built-in functions: Built-in functions and library routines are subroutines that are already written, tested and ready to use: they save time and reduce errors.
- Constant:
CONSTANT Name = literal, declared at the start, never assigned again. - Division: / gives a REAL; DIV gives the whole-number quotient; MOD gives the remainder.
- Strings: positions start at 1; MID(s, start, length); join with &.
- Random integers: INT(RAND(n)) gives 0 to n − 1; add the lowest value you want.
One picture every idea returns to
A variable is a named memory location whose value can change while the program runs; declare it with DECLARE Name : TYPE and give it a value with the assignment operator ←. A constant is declared once with CONSTANT Name = value, using a literal only, and can never be changed. Expressions combine values with arithmetic operators (+ - * / DIV MOD), relational operators and the logical operators AND, OR, NOT. Built-in functions and library routines are pre-written, pre-tested subroutines such as LENGTH, MID and INT.
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, Name it, store it, use it.. Every program starts with data: variables that change, constants that do not, and expressions that combine them. 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: Declare, initialise, assign | Exam questions give you a design as a program flowchart or as structured English and ask for pseudocode. Model the worked example Structured English to pseudocode on the board, one line at a time. Your turn: With the ticket program above, what is output when 4 is input? | Whole class, then pairs |
| 13 to 21 min | Teach and check: Operators and expressions | An expression is anything that evaluates to a single value. Model the worked example Evaluate step by step on the board, one line at a time. Your turn: Seconds holds 437. Write two assignment statements that set Minutes and Secs so that 437 seconds is shown as 7 minutes 17 seconds. | Pairs |
| 21 to 30 min | Teach and check: Built-in functions | Built-in functions and library routines are subroutines that are already written, tested and ready to use: they save time and reduce errors. Project tab 7 of the lab (9618 pseudocode: MID and string handling) and let a student drive it while the class predicts. Model the worked example Build a username on the board, one line at a time. Your turn: Explain why INT(RAND(6)) + 1 always gives a whole number from 1 to 6. | 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, 21 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 Built-in functions, 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 |
|---|---|
| CONSTANT VAT = Price * 0.2 is not allowed: a constant must be a literal. | And a constant can never appear on the left of ← later in the program. |
| 17 / 5 is 3.4, not 3. | If a question says the result must be an INTEGER, the mark is for DIV (or INT), not /. |
| In the 9618 guide UCASE and LCASE take a single CHAR, and string positions start at 1. | To change a whole string, loop through it with MID one character at a time. |
Variables, constants and built-in functions: worksheet
6 questions, 21 marks. Written in the style of the papers; no past paper question is reproduced.
Explain the difference between a variable and a constant.
A holds 23 and B holds 4. Give the value of each expression.
(a) A DIV B (b) A MOD B (c) A / B (d) (A > 20) AND (B MOD 2 = 1)
Write pseudocode for this structured English. Declare everything you use.
1. SET Pi to 3.142 (this value never changes)
2. INPUT the radius of a circle
3. CALCULATE the area as Pi multiplied by the radius squared
4. OUTPUT a message and the area
Code holds the string "CS9618-AS". State the value returned by:
(a) LENGTH(Code) (b) MID(Code, 3, 4) (c) RIGHT(Code, 2)
A full name such as Ada Lovelace contains exactly one space. Write pseudocode that inputs a full name and outputs the initials, for example AL. Use the functions LENGTH and MID.
Write pseudocode to generate a random whole number from 10 to 20 inclusive, store it in Number, and output Even or Odd as appropriate.
Answer key and marking notes
- A variable is a named memory location whose value can change while the program runs.
- A constant is given a (literal) value when it is declared and that value cannot change while the program runs.
- (a) 5
- (b) 3
- (c) 5.75
- (d) FALSE: A > 20 is TRUE but 4 MOD 2 = 0, so B MOD 2 = 1 is FALSE, and TRUE AND FALSE is FALSE.
CONSTANT Pi = 3.142DECLARE Radius : REALandDECLARE Area : REALINPUT RadiusandArea ← Pi * Radius * RadiusOUTPUT "Area is ", Area
- (a) 9
- (b) "9618"
- (c) "AS"
- Declare FullName, Initials (STRING) and Index (INTEGER);
INPUT FullName. Initials ← MID(FullName, 1, 1)to take the first letter.FOR Index ← 2 TO LENGTH(FullName)...NEXT Index.IF MID(FullName, Index, 1) = " " THEN Initials ← Initials & MID(FullName, Index + 1, 1)with ENDIF.OUTPUT Initialsafter the loop.
Number ← INT(RAND(11)) + 10(RAND(11) gives 0 to below 11, INT gives 0 to 10).IF Number MOD 2 = 0 THENOUTPUT "Even"ELSEOUTPUT "Odd"ENDIF.
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 about a constant in 9618 pseudocode is correct?
- AIt is given a literal value when it is declared, and that value cannot change while the program runs
- BIt can be given its value by an expression that uses other constants, such as Rate * 2
- CIt must be given a new value with the assignment operator before it is first used
- DIt is declared with DECLARE and a data type, in exactly the same way as a variable
A holds 29 and B holds 6. What is the value of A DIV B + A MOD B?
- A9
- B4
- C10
- D9.83
Word holds the string "ALGORITHM". What is the value of MID(Word, 3, 4) & RIGHT(Word, 2)?
- A"GORIHM"
- B"GOHM"
- C"ORITHM"
- D"LGORHM"
Which statement always stores a random whole number from 5 to 12 inclusive in N?
- A
N ← INT(RAND(8)) + 5 - B
N ← INT(RAND(12)) + 5 - C
N ← INT(RAND(7)) + 5 - D
N ← INT(RAND(8)) + 4
Seconds holds 7384. This pseudocode is run:
H ← Seconds DIV 3600 M ← (Seconds MOD 3600) DIV 60 S ← Seconds MOD 60 OUTPUT H, ":", M, ":", SWhat is output?
- A2:3:4
- B2:123:4
- C2:3:184
- D2.05:3.07:4
Which numbered line is not valid 9618 pseudocode?
01 CONSTANT MaxScore = 100 02 CONSTANT HalfScore = MaxScore / 2 03 DECLARE Score : INTEGER 04 Score ← INT(RAND(MaxScore)) + 1 05 OUTPUT "Score: ", Score
- ALine 02
- BLine 04
- CLine 01
- DLine 05
Quiz key
CONSTANT Name = value takes a literal only, and the value is fixed for the whole run. An expression such as Rate * 2 is not allowed after the =. A constant can never appear on the left of ← later in the program, and it is declared with CONSTANT, not DECLARE with a data type.
29 DIV 6 = 4 (because 4 × 6 = 24) and 29 MOD 6 = 5 (29 − 24), so the sum is 9. The value 4 is the DIV part alone. 10 comes from rounding 4.83 up to 5 instead of truncating. 9.83 uses / (giving 4.83) instead of DIV.
Position 3 is G, and four characters from there are G, O, R, I. RIGHT(Word, 2) gives "HM", and & joins them: "GORIHM". "GOHM" treats 3 and 4 as start and end positions. "ORITHM" counts positions from 0. "LGORHM" starts one character too early, at position 2.
There are 8 values from 5 to 12. INT(RAND(8)) gives 0 to 7, and adding 5 gives 5 to 12. INT(RAND(12)) + 5 can reach 16. INT(RAND(7)) + 5 stops at 11, so 12 is never produced. INT(RAND(8)) + 4 gives 4 to 11.
7384 DIV 3600 = 2 and 7384 MOD 3600 = 184. Then 184 DIV 60 = 3, and 7384 MOD 60 = 4 (7384 = 123 × 60 + 4), so the output is 2:3:4. 123 is Seconds DIV 60, the total number of minutes, ignoring the hours already taken out. 184 is the remainder after the hours, not the seconds. 2.05 and 3.07 come from using / instead of DIV.
A constant must be given a literal value, never an expression or another constant, so line 02 is invalid (it would have to be CONSTANT HalfScore = 50). Line 04 is fine: a constant can be used inside an expression. Line 01 declares a constant with a literal correctly, and line 05 outputs a string and a variable separated by a comma, which OUTPUT allows.
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.