Spec & Goals 3 min
AQA Spec 3.2.6 · Data structures (records)
By the end of this lesson you can:
- Describe a record as a group of related fields that may be different data types.
- Access a field with the
record.fieldnotation. - Store many records in an array of records and explain how it differs from an array.
Warm-Up 5 min
Last lesson you used an array to store many items of the same data type.
Quick starter
Could a single array store a pupil's name (text), age (number) and membership status (true/false) together? Why might that be awkward?
Reveal the answer
An array holds one data type only, so mixing text, a number and a Boolean is awkward. A record is built for exactly this — related fields of different types under one name.
Key Concept — records and fields 14 min
A record groups related fields that may each be a different data type. Think of one row of a table.
A member record might look like this:
| Field | Data type | Example value |
|---|---|---|
name | String | "Aisyah" |
age | Integer | 15 |
member | Boolean | True |
Accessing a field
You read or write one field with the record.field notation — for example member1.name gives the name field.
An array of records
To store many records — a whole table of data — you put them in an array of records. Each element is one record; each record holds several fields.
Worked Example — a Student record 12 min
Problem: define a Student record with the fields name, form and mark, store several students, and read one field.
AQA pseudo-code
RECORD Student
name : String
form : String
mark : Integer
ENDRECORD
student1 ← Student("Aisyah", "5A", 72)
student2 ← Student("Hafiz", "5B", 65)
OUTPUT student1.name
OUTPUT student1.markThe first OUTPUT reads the name field and the second reads the mark field of student1.
Storing many — an array of records
students ← [student1, student2] OUTPUT students[1].form
Element 1 is student2, so this outputs 5B. The index picks the record; the dot picks the field.
The same idea in Python
# Python has no RECORD keyword; a dictionary (or class) is used student1 = {"name": "Aisyah", "form": "5A", "mark": 72} student2 = {"name": "Hafiz", "form": "5B", "mark": 65} print(student1["name"]) students = [student1, student2] print(students[1]["form"])
Note: Python uses dictionaries or classes to represent records — there is no RECORD keyword.
Try It Yourself 12 min
Goal: A record book has fields title, author and pages. Write the line that outputs the author of book.
Hint: use the record.field notation.
Goal: Define a RECORD called Member with fields name (String), age (Integer) and active (Boolean).
Hint: list each field with its data type between RECORD and ENDRECORD.
Goal: Using your Member record, create an array of records called members with two members, then write the line that outputs the age of the second member.
📝 Exam Practice 10 min
Answer the way the examiner expects — the command word and the marks tell you how much to write.
Give one difference between an array and a record.
Mark scheme
- An array stores elements that are all the same data type (1).
- A record stores related fields that may be different data types (1).
A record stores a person's details. State the most suitable data type of the age field.
Mark scheme
- Integer (1). Accept: whole number.
A record student1 has a name field. Write the line that outputs the name field of student1.
Mark scheme
OUTPUT student1.name(1).
Define the term field as used in a record.
Mark scheme
- A single named item of data within a record (1).
Recap & Key Terms 3 min
A record groups related fields that may be different data types, like one row of a table. You reach a field with record.field. Storing many records in an array of records builds a whole table — unlike a plain array, which holds one data type only.
- Record
- A data structure grouping related fields, which may be of different data types, under one name.
- Field
- A single named item of data inside a record, accessed with
record.field. - Array of records
- An array whose elements are records — used to store a table of related data.
Homework 1 min
Task (≤ 15 min): Define a RECORD called Pet with the fields name (String), species (String) and age (Integer). Then write the line that outputs the species of a pet record called pet1.
Model answer
RECORD Pet
name : String
species : String
age : Integer
ENDRECORD
OUTPUT pet1.speciesAward marks for: three correctly typed fields (1), correct RECORD … ENDRECORD structure (1), output the field with pet1.species (1).