Record Structures (Cambridge (CIE) A Level Computer Science): Revision Note
Exam code: 9618
Purpose of records
What is a record?
A record is a composite data structure used to store a collection of related data items
Each item can be of a different data type
It allows a programmer to group related values under one identifier
Records help create a more structured and readable approach to storing and managing data
A record contains a fixed number of fields, each with its own name and type
In pseudocode, a record can by declared as:
TYPE <Typename>
DECLARE <identifier> : <data type>
DECLARE <identifier> : <data type>
DECLARE <identifier> : <data type>
..
..
ENDTYPE
Suppose we want to store information about a car
We can define a record type like this:
TYPE Car
DECLARE Make : STRING
DECLARE Model : STRING
DECLARE Colour : STRING
DECLARE Price : REAL
DECLARE DateOfRegistration : DATE
ENDTYPE
We can then create a variable of this type:
DECLARE MyCar : Car
And assign values to its fields:
MyCar.Make ← "Toyota"
MyCar.Model ← "Yaris"
MyCar.Colour ← "Red"
MyCar.Price ← 14995.99
MyCar.DateOfRegistration ← "12/03/2022"
To read from the record we can:
OUTPUT "Make: ", MyCar.Make
OUTPUT "Model: ", MyCar.Model
OUTPUT "Colour: ", MyCar.Colour
OUTPUT "Price: £", MyCar.Price
OUTPUT "Date of Registration: ", MyCar.DateOfRegistration
Examiner Tips and Tricks
Records in programming are a type of data structure used to group related data in your code
These are not the same as records in a database, which refer to a complete set of fields on a single entity in a table (row)
Key features of records
Feature | Explanation |
---|---|
Can store different data types | Unlike arrays, records are not limited to a single type |
Fields are named | Each item in the record has a meaningful identifier |
Offers structured storage | Easier to manage complex data about real-world entities |
You've read 0 of your 5 free revision notes this week
Unlock more, it's free!
Did this page help you?