SLIDE 1
CSZone.co.uk
Click to advance · Arrow keys also work
CAIE 9618 · Paper 2 · Topic 2.2.3

Records &
Composite Types

TYPE…ENDTYPE · Fields · Arrays of Records · Real-World Modelling

CSZone Cambridge International AS & A Level Computer Science 9618
What is a Record?

Grouping Related Data of Different Types

A record is a composite data type that groups together several fields of different data types under a single name. Unlike arrays, records can store heterogeneous data. In CAIE pseudocode, records are defined using TYPE…ENDTYPE.
ARRAYS vs RECORDS
Arrays: same type, accessed by index.
Records: mixed types, accessed by field name.
Both are structured (composite) data types.
WHY USE RECORDS?
Model real-world entities (students, products, employees). Keep related data together. Improves code readability. Pass multiple related values to procedures.
Defining and Using Records

TYPE…ENDTYPE Declaration

DEFINE THE RECORD TYPE
TYPE Student
name : STRING
age : INTEGER
grade : CHAR
score : REAL
ENDTYPE
DECLARE A VARIABLE AND ASSIGN
DECLARE s1 : Student
s1.name <- "Ali"
s1.age <- 17
s1.grade <- 'A'
s1.score <- 92.5
OUTPUT s1.name, s1.score
Access fields using dot notation: variable.fieldname. The type definition is a blueprint — declare variables of that type separately.
Arrays of Records

Store Multiple Records in an Array

An array of records lets you store multiple instances of the same record type — e.g. all students in a class.
DECLARE ARRAY OF RECORDS
// Using Student type from before
DECLARE class : ARRAY[1:30] OF Student
ASSIGN VALUES
class[1].name <- "Leila"
class[1].score <- 88.0
class[2].name <- "James"
OUTPUT ALL NAMES
FOR i <- 1 TO 30
OUTPUT class[i].name
NEXT i
Access pattern: array[index].fieldname — combines array indexing with dot notation.
Exam Practice

Cambridge-style questions

Question 1
Define a record type called Product with fields: productID (INTEGER), name (STRING), price (REAL), inStock (BOOLEAN). Then write pseudocode to declare an array of 100 products and output the name of any product where price > 50.00.
6 marks
TYPE Product // 1 mark — TYPE...ENDTYPE structure
productID : INTEGER
name : STRING // 1 mark — correct fields and types
price : REAL
inStock : BOOLEAN
ENDTYPE
DECLARE catalogue : ARRAY[1:100] OF Product // 2 marks
FOR i <- 1 TO 100 // 1 mark
IF catalogue[i].price > 50.00 THEN // 1 mark
OUTPUT catalogue[i].name
ENDIF
NEXT i
Common Mistakes

Don't lose easy marks

1
Forgetting ENDTYPE — every TYPE block must close with ENDTYPE. Missing this is a syntax error and will cost marks. Similarly, ENDTYPE not ENDRECORD — CAIE pseudocode uses ENDTYPE.
2
Using incorrect dot notation — CAIE uses variable.field (e.g. s1.name). Some candidates write s1[name] or s1("name") which is wrong. Field access always uses a dot.
3
Confusing TYPE definition with DECLARE — TYPE creates a blueprint (no memory allocated). DECLARE creates an actual variable of that type (memory allocated). You must do both: define the type, then declare a variable of that type.
Topic Summary — 2.2.3

What You Need to Know

RECORD DEFINITION
TYPE Name
fieldname : TYPE
ENDTYPE
Blueprint — defines structure only
VARIABLE DECLARATION
DECLARE varname : RecordType
Access fields: varname.fieldname <- value
Arrays: DECLARE arr : ARRAY[1:n] OF Type
ARRAYS OF RECORDS
arr[i].field — combine array index + dot notation
Use FOR loop to traverse all records
Best for storing sets of related entities
CSZone

Next Video

2.3.1
Stacks
LIFO · Push · Pop · Peek · isEmpty · Stack Pointer
Head to CSZone.co.uk for the complete worksheet, quiz, and interactive tools