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. When several items of different types describe one thing, a record keeps them together under a single identifier.
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.
Pick the type from what the data is and what the program must do with it. A value that is never used in arithmetic is often better stored as a string, even if it is made of digits.
| Type | Holds | Literal | Typical use |
|---|---|---|---|
| INTEGER | a whole number | 5, −3 | number of tickets, age in years |
| REAL | a number with a fractional part | 4.7, 0.0 (a digit on each side of the point) | price, temperature, average |
| CHAR | exactly one character | 'B' (single quotes) | grade, menu choice, one-letter code |
| STRING | zero or more characters | "Khan", "" (double quotes) | name, postcode, phone number |
| BOOLEAN | one of two logical values | TRUE, FALSE | flags such as Found, IsMember |
| DATE | a valid calendar date | 14/03/2009 (state the format: dd/mm/yyyy) | date of birth, due date |
DECLARE TicketsSold : INTEGER DECLARE Price : REAL DECLARE Grade : CHAR DECLARE Phone : STRING DECLARE IsMember : BOOLEAN DECLARE DueDate : DATE
"Phone number: INTEGER because it is a number" loses the mark. Digits that are an identifier, not a quantity, belong in a STRING.
A record type is a template. Defining it creates no data; it tells the program which fields every variable of that type will have and the data type of each one.
TYPE BookRecord
DECLARE BookID : STRING
DECLARE Title : STRING
DECLARE Copies : INTEGER
DECLARE Cost : REAL
DECLARE DueDate : DATE
DECLARE OnLoan : BOOLEAN
ENDTYPE
DECLARE ThisBook : BookRecord
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.
Four quick checks. Each correct answer earns XP and records this skill on your profile.
Which data type should store the average of a set of test marks?
What is the purpose of a record structure?
StudentRecord has a field Surname. Pupil1 is declared as StudentRecord. Which statement is correct?
Which literal is a valid REAL in 9618 pseudocode?
Use dot notation to reach a field: the variable name, a full stop, then the field name. A whole record can be copied in one assignment if both variables have the same type, and an array of records stores many of them.
ThisBook.BookID ← "B0457" ThisBook.Title ← "Dune" ThisBook.Copies ← 3 ThisBook.Cost ← 12.50 ThisBook.DueDate ← 21/11/2026 ThisBook.OnLoan ← TRUE OUTPUT ThisBook.Title, " has ", ThisBook.Copies, " copies" DECLARE Library : ARRAY[1:500] OF BookRecord Library[1] ← ThisBook
Count ← 0.FOR Index ← 1 TO 500.IF Library[Index].OnLoan = TRUE THEN.OUTPUT Library[Index].Title and Count ← Count + 1; after NEXT Index, output Count.DECLARE Count : INTEGER
DECLARE Index : INTEGER
Count ← 0
FOR Index ← 1 TO 500
IF Library[Index].OnLoan = TRUE THEN
OUTPUT Library[Index].Title
Count ← Count + 1
ENDIF
NEXT Index
OUTPUT Count, " books on loan"Library[12].Copies ← Library[12].Copies + 1: the index goes on the array name, the field name comes after the dot.The index belongs to the array, not the field: Library[12].Copies, never Library.Copies[12].
Unlocks once the four checks above are done. Worth more XP, written to AS Paper 1 and Paper 2 standard.
A program stores a member's postcode, such as CB2 1EW. Which data type is most appropriate?
Which line correctly declares an array that can hold 40 records of type PlayerRecord?
Which statement about a record type is true?
Readings is an ARRAY[1:24] OF SensorRecord with a REAL field Temp. Which expression gives the temperature of the 5th reading?
This skill is now recorded on your profile. Keep the chain going.