The shape of the lesson
By the end of the lesson, learners can
- Choosing a data type: Pick the type from what the data is and what the program must do with it.
- Defining a record: A record type is a template.
- Reading and writing records: Use dot notation to reach a field: the variable name, a full stop, then the field name.
- Six types: INTEGER, REAL, CHAR, STRING, BOOLEAN, DATE; justify each from the data and its use.
- Digits that are not quantities (phone numbers, IDs) are STRING.
- Record:
TYPE Name, a DECLARE line per field,ENDTYPE; then DECLARE a variable of that type. - Access:
Variable.Field; in an array of records,Array[Index].Field.
One picture every idea returns to
A data type decides which values a variable can store and which operations are allowed on it. 9618 pseudocode uses INTEGER, REAL, CHAR, STRING, BOOLEAN and DATE. A record is a composite (user-defined) data type that holds a set of related data items, called fields, which can be of different data types, all under one identifier. It is defined with TYPE ... ENDTYPE and each field is accessed with dot notation, such as Pupil1.YearGroup.
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, The right type for the job.. Every item of data in a program has a data type that fixes what values it can hold and what you can do with it. 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: Choosing a data type | Pick the type from what the data is and what the program must do with it. Model the worked example Justify each choice on the board, one line at a time. Your turn: A telephone number such as 07700900123 is to be stored. Should it be INTEGER or STRING? Give a reason. | Whole class, then pairs |
| 13 to 21 min | Teach and check: Defining a record | A record type is a template. | Pairs |
| 21 to 30 min | Teach and check: Reading and writing records | Use dot notation to reach a field: the variable name, a full stop, then the field name. Model the worked example Process an array of records on the board, one line at a time. Your turn: Write one statement that adds 1 to the number of copies of the book stored in element 12 of Library. | Jigsaw |
| 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 Reading and writing records, 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.
Jigsaw
Split the content into expert pieces. Expert groups master one piece each, then regroup so every home team has one expert per piece, and each expert teaches their piece to the team.
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 |
|---|---|
| "Phone number: INTEGER because it is a number" loses the mark. | Digits that are an identifier, not a quantity, belong in a STRING. |
| TYPE... | ENDTYPE only defines the type. You still need DECLARE ThisBook: BookRecord before any data can be stored. Writing BookRecord.Title ← "Dune" uses the type name, not a variable, and earns no mark. |
| The index belongs to the array, not the field: Library[12].Copies, never Library.Copies[12]. | Return to Reading and writing records: ask a pair to state the correct version and show it on the lab before moving on. |
Data types and records: worksheet
6 questions, 21 marks. Written in the style of the papers; no past paper question is reproduced.
Explain what is meant by a record structure.
A cinema stores, for each film showing: the film title, the screen number (1 to 12), the ticket price, the date of the showing, whether it is 3D, and an age rating of one character. State the most appropriate data type for four of these items.
Write pseudocode to define a record type CarRecord with fields for a registration number, the make, the year of manufacture, the price and whether the car has been sold. Then declare a variable NewCar of this type.
Using CarRecord and NewCar, write pseudocode statements to store a car with registration AB12 CDE, make Toyota, year 2021, price 15995.00, not yet sold, and then output its make and price.
Stock is an ARRAY[1:200] OF CarRecord. Write pseudocode to output the registration of every car that is not sold and was made before 2015, and then the total price of those cars.
A programmer stores the cars in five separate 1D arrays (one per field) instead of one array of records. Give two advantages of using an array of records.
Answer key and marking notes
- A (composite / user-defined) data type that holds a set of related data items (fields).
- The fields can be of different data types and are referred to by one identifier.
- Title: STRING.
- Screen number: INTEGER.
- Ticket price: REAL.
- Date: DATE; Is 3D: BOOLEAN; Age rating: CHAR (any four correct, 1 mark each).
TYPE CarRecord...ENDTYPEenclosing the fields.DECLARE Registration : STRINGandDECLARE Make : STRING.DECLARE Year : INTEGER,DECLARE Price : REAL,DECLARE Sold : BOOLEAN.DECLARE NewCar : CarRecordafter the type definition.
NewCar.Registration ← "AB12 CDE"andNewCar.Make ← "Toyota".NewCar.Year ← 2021,NewCar.Price ← 15995.00,NewCar.Sold ← FALSE.OUTPUT NewCar.Make, " ", NewCar.Price.
- Initialise
Total ← 0before the loop. FOR Index ← 1 TO 200...NEXT Index.IF Stock[Index].Sold = FALSE AND Stock[Index].Year < 2015 THEN.- Inside:
OUTPUT Stock[Index].RegistrationandTotal ← Total + Stock[Index].Price. OUTPUT Totalafter the loop.
- All the data about one car is kept together under one identifier and one index.
- A whole car can be moved, copied or swapped (for example when sorting) in one assignment, so the fields cannot get out of step.
- Only one array needs to be declared and passed to subroutines (any two, with explanation for the third mark).
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.
A program stores a customer's mobile number, such as 07700900461. Which data type is most appropriate?
- ASTRING
- BINTEGER
- CREAL
- DCHAR
A school stores, for each student: the initial letter of their house, the number of merits they have earned and whether they have paid for a trip. Which data types are most appropriate, in that order?
- ACHAR, INTEGER, BOOLEAN
- BSTRING, REAL, BOOLEAN
- CCHAR, INTEGER, STRING
- DCHAR, REAL, CHAR
What is the main purpose of a record structure?
- ATo hold related data items, which may be of different data types, under one identifier
- BTo hold a fixed number of values that all have the same data type
- CTo keep data on secondary storage after the program has ended
- DTo store items so that the last one added is the first one removed
Team is declared as ARRAY[1:20] OF PlayerRecord, and PlayerRecord has an INTEGER field Goals. Which statement adds 1 to the goals of the player in element 3?
- A
Team[3].Goals ← Team[3].Goals + 1 - B
Team.Goals[3] ← Team.Goals[3] + 1 - C
PlayerRecord[3].Goals ← PlayerRecord[3].Goals + 1 - D
Goals[3].Team ← Goals[3].Team + 1
This pseudocode contains one error. Which line is it on, and why?
1 TYPE PetRecord 2 DECLARE Name : STRING 3 DECLARE Age : INTEGER 4 ENDTYPE 5 DECLARE MyPet : PetRecord 6 PetRecord.Name ← "Bo" 7 MyPet.Age ← 3
- ALine 6: it assigns to the type name PetRecord instead of the variable MyPet
- BLine 5: a variable of a record type cannot be declared with DECLARE
- CLine 7: a field of a record cannot be given a value by assignment
- DLine 1: TYPE must be followed by a colon and a built-in data type
Stock is an ARRAY[1:4] OF ItemRecord with a REAL field Price and an INTEGER field InStock. The four records hold (Price, InStock): (2.50, 4), (1.20, 0), (3.00, 2), (0.80, 10). What is output?
Total ← 0.0
FOR i ← 1 TO 4
IF Stock[i].InStock > 0 THEN
Total ← Total + Stock[i].Price * Stock[i].InStock
ENDIF
NEXT i
OUTPUT Total- A24.0
- B6.3
- C7.5
- D16
Quiz key
A phone number is an identifier made of digits, not a quantity: it is never added or multiplied, and as an INTEGER the leading zero would be lost. REAL has the same problem and adds a fractional part that makes no sense, and CHAR holds only one character.
One letter is a CHAR, a count of merits is always a whole number so INTEGER, and paid or not paid has two values so BOOLEAN. STRING works for one letter but is not the most appropriate, and merits never have a fractional part, so REAL is wrong. Storing a yes or no answer as a STRING or CHAR invites invalid values such as "maybe".
A record is a composite type whose fields can have different data types, all reached through one identifier. Same-type values in a fixed number of elements describe an array, permanent storage needs a file, and last in, first out describes a stack.
Team[3] is one PlayerRecord, and .Goals selects its field. The index belongs to the array, not to the field, so Team.Goals[3] is wrong. PlayerRecord is the type name and holds no data, and Goals[3].Team reverses array and field.
PetRecord is only the definition of the type; data is stored in a variable of that type, so line 6 should be MyPet.Name ← "Bo". Line 5 is exactly how a record variable is declared, line 7 is a valid field assignment using dot notation, and a record type is written TYPE followed by its name, with its fields declared inside.
Records 1, 3 and 4 have stock: 2.50 × 4 + 3.00 × 2 + 0.80 × 10 = 10.0 + 6.0 + 8.0 = 24.0. 6.3 adds only the prices of the items in stock, 7.5 adds every price, and 16 is the total number of items, not their value.
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.