Show understanding of the purpose of a record structure to hold a set of data of different data types under one identifier.
| Primitive type (syllabus) | Typical use‑case | Cambridge pseudocode example |
|---|---|---|
| INTEGER | Counts, ages, indexes | age : INTEGER |
| REAL | Measurements, averages, GPA | gpa : REAL |
| CHAR | Single‑character flags (e.g. gender ‘M’/‘F’) | gender : CHAR |
| STRING | Names, addresses, free‑text | name : STRING[30] |
| BOOLEAN | True/false conditions | isFullTime : BOOLEAN |
| DATE | Calendar dates | enrolDate : DATE |
| ARRAY | Homogeneous collections indexed by an integer | marks : ARRAY[1..10] OF INTEGER |
| FILE | External storage of records or arrays | studentFile : FILE |
A record (called a structure in some languages) is a composite data type that groups together a fixed number of elements, called fields. Each field may have a different primitive type, but all fields are accessed through a single identifier – the record variable name.
WRITE/READ statement.For each of the following real‑world situations, list the fields you would need, decide which primitive type is most appropriate for each field, and write the Cambridge‑style record definition.
Tip: Use CHAR only for a single character (e.g. a grade code). Use STRING[n] when you need more than one character. Use INTEGER for whole numbers, REAL for values that may have a fractional part, and DATE for calendar dates.
RECORD Student
name : STRING[30] // full name
age : INTEGER // years
gpa : REAL // grade point average
enrolDate : DATE // date of enrolment
END RECORD
Student – field summary| Field | Data type | Typical size (bytes) on a 32‑bit machine |
|---|---|---|
| name | STRING[30] | 30 |
| age | INTEGER | 4 |
| gpa | REAL | 8 |
| enrolDate | DATE | 8 |
SizeStudent = 30 + 4 + 8 + 8 = 50 bytes
Two padding bytes are inserted after name to reach the next multiple of 4.
SizeStudent = (30 + 2) + 4 + 8 + 8 = 52 bytes
Student record showing each field and any padding bytes.
DECLARE student1 : Student
student1.name := "Alice Johnson"
student1.age := 20
student1.gpa := 3.75
student1.enrolDate := "2023‑09‑01"
The Cambridge syllabus expects the WRITE and READ statements to operate on a record variable. This stores the record in a binary file, preserving the exact layout (including any padding).
OPEN studentFile FOR WRITE AS "students.dat"
WRITE studentFile, student1 // whole record written at once
CLOSE studentFile
DECLARE student2 : Student
OPEN studentFile FOR READ AS "students.dat"
READ studentFile, student2 // whole record read at once
CLOSE studentFile
OPEN studentFile FOR WRITE AS "students.txt"
WRITE studentFile, student1.name, student1.age,
student1.gpa, student1.enrolDate
CLOSE studentFile
PROCEDURE printStudent(s : Student) // parameter passed by reference
OUTPUT "Name: " & s.name
OUTPUT "Age: " & s.age
OUTPUT "GPA: " & s.gpa
OUTPUT "Enrolled: " & s.enrolDate
END PROCEDURE
CALL printStudent(student1)
FUNCTION isHonours(s : Student) : BOOLEAN // returns TRUE if GPA ≥ 3.5
IF s.gpa >= 3.5 THEN
RETURN TRUE
ELSE
RETURN FALSE
END IF
END FUNCTION
DECLARE honours : BOOLEAN
honours := isHonours(student1)
OUTPUT "Honours student? " & honours
VALUE if you need this behaviour.A record describes the data representation of an abstract data type. The ADT also defines the operations that can be performed on that data.
| Aspect | Record (concrete) | ADT (abstract) |
|---|---|---|
| Data representation | RECORD Student … END RECORD | “Student” ADT – a logical entity that stores name, age, GPA, enrolDate. |
| Operations | Procedures/functions such as printStudent, isHonours | Insert, Delete, Search, Update (defined in the specification of the Student ADT). |
| Implementation example | Array of Student records used as a simple list. | List ADT that stores Student objects. |
CONST MAX_STUDENTS = 100
DECLARE studentList : ARRAY[1..MAX_STUDENTS] OF Student
DECLARE n : INTEGER := 0 // current number of students
PROCEDURE addStudent(s : Student)
IF n < MAX_STUDENTS THEN
n := n + 1
studentList[n] := s
END IF
END PROCEDURE
FUNCTION findByName(searchName : STRING[30]) : INTEGER // returns index or 0
FOR i FROM 1 TO n DO
IF studentList[i].name = searchName THEN
RETURN i
END IF
END FOR
RETURN 0
END FUNCTION
HIGH‑LEVEL: storeStudentResults()
1. Define the Student record ← see §5
2. Open the binary file for writing ← see §8.1
3. For each student:
a. Read data from the keyboard
b. Fill a Student variable
c. WRITE the variable to the file
4. Close the file
Each step can be turned into its own procedure (e.g. readStudentData, writeStudentRecord), illustrating the decomposition required by the syllabus.
marks : ARRAY[1..5] OF INTEGER).WRITE/READ demonstrates the link between memory and storage.Record: a composite data type that groups a fixed set of fields of possibly different primitive types.
Field: an individual component of a record, identified by a name and a data type.
Identifier: the name given to a variable, record type, or field.
Dot operator (.): syntax used to access a field of a record (e.g. student.age).
Padding: unused bytes added by the hardware to satisfy alignment requirements; they increase the total size of a record.
ADT (Abstract Data Type): a logical description of a data structure that specifies the operations that can be performed, without fixing the implementation.
Parameter passing: the method by which arguments are supplied to procedures/functions (by reference – default, or by value).
RECORD … END RECORD and the dot operator (.) for field access.WRITE/READ statement.Your generous donation helps us continue providing free Cambridge IGCSE & A-Level resources, past papers, syllabus notes, revision questions, and high-quality online tutoring to students across Kenya.