Skip to content
Cambridge AS & A Level9618

Data Types and Records

Computer Science 9618 Chapter Notes

Last updated November 2026

ShareWhatsAppPost

Data Types and Records notes as a printable PDF.

Read online free. Download a watermarked copy with a free account.

Read the notes

The full Data Types and Records notes as text: skim, search, and jump between subtopics.

~13 min read

1. Data types

Pseudocode uses these data types: `INTEGER`, `REAL`, `CHAR`, `STRING`, `BOOLEAN`, `DATE`, `ARRAY` and `FILE`. Choose the type from the value and the comment about it.

A whole number such as 1345 is INTEGER. A number with a decimal part such as 15.75 is REAL. A single letter such as 'S' is `CHAR`. Text such as "Wong", or a code that may contain letters and numbers such as "1B", is STRING. TRUE or FALSE is BOOLEAN. A calendar value such as 19/02/1983 is `DATE`.

A STRING value is written in double quotes and a CHAR value in single quotes. Name each variable for what it holds, for example `MemberName`.

Examiner insight

“Variable names such as 'flag' for row 2 and 'Date' for row three were too imprecise. 'Date' is also the name of a data type and therefore a keyword.” “One of the most frequent errors was the use of a less than meaningful variable name. A typical example of this was simply using name for the name of the customer.”

Worked example 14 marks

A program is being developed to help manage the membership of a football club.

Complete the following identifier table.

Example valueExplanationVariable nameData type
`"Wong"`The preferred name of the member joining the football club
`FALSE`A value to indicate whether an existing member of the club lives at the same address
`19/02/1983`When the member joined the football club
`1345`The number of points a member has earned. Members of the club earn points for different activities.
  1. 1

    `"Wong"`: variable `MemberName`, type `STRING` [1]

  2. 2

    `FALSE`: variable `FamilyMember`, type `BOOLEAN` [1]

  3. 3

    `19/02/1983`: variable `StartDate`, type `DATE` [1]

  4. 4

    `1345`: variable `Points`, type `INTEGER` [1]

2. Why use a record

A record structure holds a set of data of different data types under one identifier. Each item in it is a field, and each field has its own name and data type.

An array holds items of one data type, so a record is the structure to choose when the items differ in type. A variable declared with the record type as its data type then holds one record.

To store many records while the program runs, use an array of records, where each element holds the data for one item.

Examiner insight

“A minority identified the use of a record and gave as a justification the fact that a record could hold different data types. The justification that the values could be stored under a single identifier was rarely seen.” “Common mistakes included 'database' and simply 'file'. Another common incorrect answer was 'an array' which by itself was not mark worthy.”

Worked example 13 marks

The following data items need to be stored for each student in a group:

  • student name (a string)
  • test score (an integer).

State a suitable data structure and justify your answer.

  1. 1

    Structure: a record [1]

  2. 2

    Justification: it allows different data types to be stored [1]

  3. 3

    ... under one identifier [1]

3. Declaring a record and an array of records

Declare the record type between `TYPE` and `ENDTYPE`. Each field has a `DECLARE` line with its name and data type.

``` TYPE Component DECLARE Item_Num : INTEGER DECLARE Reject : BOOLEAN DECLARE Stage : CHAR DECLARE Limit_1 : REAL DECLARE Limit_2 : REAL ENDTYPE ```

Then declare the array with the record type as its element type. The bounds `[1:2000]` give 2000 elements, and `[2000]` or `[0:1999]` are credited too.

``` DECLARE Item : ARRAY [1:2000] OF Component ```

Examiner insight

“A small number of candidates lost marks for mentioning the use of a 2D array instead of just an array or preferably a 1D array.”

Worked example 16 marks

The data items for each rental will be held in a record structure of type RentalRecord

(i) Write pseudocode to declare the record structure for type RentalRecord

(ii) A 1D array Rental containing 500 elements is used to store the data for all rental records.

Write pseudocode to declare the Rental array.

The programmer has started to define the items that will be needed:

ItemExample valueComment
`RentalID``"AB1234"`a unique alpha-numeric value
`CarID``241`a numeric value used as an array index
`DisCode``'S'`a letter indicating the type of discount offered
`Start``13/06/2025`when the rental starts
`Duration``7`the number of days of the rental
`Completed``FALSE`TRUE when the car is returned and the rental charge paid
  1. 1

    `TYPE RentalRecord` first and `ENDTYPE` last [1]

  2. 2

    ``` DECLARE RentalID : STRING DECLARE CarID : INTEGER ``` [1]

  3. 3

    ``` DECLARE DisCode : CHAR DECLARE Start : DATE ``` [1]

  4. 4

    ``` DECLARE Duration : INTEGER DECLARE Completed : BOOLEAN ``` [1]

  5. 5

    ``` DECLARE Rental : ARRAY[1:500] OF RentalRecord ``` [2]

4. Why use an array of records

Each record holds the fields for one item, and the array holds all the records under one identifier. This gives three benefits.

A loop gives iteration through the records. An index gives direct access to one record, for example `Item[1].Stage`. The code is simpler, with less duplicated code, so the program is easier to write, understand, maintain, test and debug.

Worked example 13 marks

The data for each item will be held in a record structure of type Component.

State three benefits of using an array of records to store the data for all items.

  1. 1

    Allows iteration: a loop can access the records [1]

  2. 2

    Use of an index to directly access a record in the array, for example `Item[1].Stage` [1]

  3. 3

    Simplifies the code: reduces duplication, so the program is easier to write, understand, maintain, test or debug [1]

5. Reading and saving field values

Use dot notation: the record variable, a dot, then the field name. To save a value, assign it to the field: `LineData.Cost ← 12.99`. To read a value, use the field in an expression or in `OUTPUT`.

In an array of records the index comes first: `Staff[Index].Attendance`.

Some records in the array may be unused. Use an impossible value in a field to mark an unused record, such as an `EmployeeNumber` below 1, so that unused elements may be recognised when processing. Test for it before using the record.

Examiner insight

“Just under half of the candidates provided the correct answer to this question. The correct answer was LineData.Cost ← 12.99”

Worked example 14 marks

A program will store attendance data about each employee of a company.

A 1D array Staff containing 500 elements will be used to store the employee records. There may be more records in the array than there are employees in the company. In this case, some records of the array will be unused.

A procedure Absentees() will output the EmployeeNumber and the Name of all employees who have an Attendance value of 90.00 or less.

Write pseudocode for the procedure Absentees().

Assume that the Staff array is global.

The data will be held in a record structure of type Employee. The fields that will be needed are:

FieldTypical valueComment
`EmployeeNumber``123`A numeric value starting from 1
`Name``"Smith,Eric"`Format: <last name>','<first name>
`Department``"1B"`May contain letters and numbers
`Born``13/02/2006`Must not be before 04/02/1957
`Attendance``97.40`Represents a percentage
  1. 1

    Procedure heading and ending, and a declared loop counter [1]

  2. 2

    Loop through all 500 elements of `Staff` [1]

  3. 3

    Skip an unused element, marked by an impossible `EmployeeNumber` such as -1: `IF Staff[Index].EmployeeNumber <> -1 THEN` [1]

  4. 4

    Test `Staff[Index].Attendance <= 90`, then output the `EmployeeNumber` and `Name` fields (the scheme has five points and a maximum of 4) [1]

  5. 5

    ``` PROCEDURE Absentees() DECLARE Index : INTEGER FOR Index ← 1 TO 500 IF Staff[Index].EmployeeNumber <> -1 THEN IF Staff[Index].Attendance <= 90 THEN OUTPUT Staff[Index].EmployeeNumber OUTPUT Staff[Index].Name ENDIF ENDIF NEXT Index ENDPROCEDURE ```

Recap

  • Pseudocode data types: INTEGER, REAL, CHAR, STRING, BOOLEAN, DATE, ARRAY, FILE.
  • Whole number: INTEGER. Decimal: REAL. One letter: CHAR. Text or letters and numbers: STRING. TRUE or FALSE: BOOLEAN. Calendar value: DATE.
  • Give each variable a meaningful name. Never use a data type name such as Date as a variable name.
  • A record holds a set of data of different data types under one identifier.
  • Declare it with TYPE, a DECLARE line for each field, then ENDTYPE.
  • Many records: DECLARE name : ARRAY [1:n] OF RecordType.
  • Access a field with dot notation: Staff[Index].Attendance.
  • Mark an unused record with an impossible field value and skip it in loops.

End-of-chapter exercise

Test yourself on the whole chapter. Work through these before moving on.

  1. Give the pseudocode data type for the variable Grade, which stores a single letter such as 'B'.1 mark
    Answer
    1. `CHAR` [1].

    Trap: `STRING` can hold the letter, but the type for one letter is `CHAR`.

  2. Complete the identifier table. Give a variable name and a data type for each row. | Example value | Explanation | | --- | --- | | `"Ms Hall"` | The name of a teacher | | `31` | The number of pupils in a class | | `62.5` | The average mark of a class in a test | | `05/11/2025` | The date of the test |4 marks
    Answer
    1. `"Ms Hall"`: `TeacherName`, `STRING` [1].
    2. `31`: `ClassSize`, `INTEGER` [1].
    3. `62.5`: `AverageMark`, `REAL` [1].
    4. `05/11/2025`: `TestDate`, `DATE` [1].

    Trap: `Date` is too imprecise as a name and is also the name of a data type.

  3. A field Department holds values such as "1B" and "3C". A programmer declares it as `INTEGER`. Explain why this is wrong.2 marks
    Answer
    1. The values contain letters as well as numbers [1].
    2. The field must be declared as `STRING` [1].

    Trap: A value that starts with a digit is not a number if it also contains letters.

  4. The data items needed for each library book are the title (a string), the number of pages (an integer) and whether it is on loan (a Boolean). State a suitable data structure and justify your answer.3 marks
    Answer
    1. Structure: a record [1].
    2. It allows different data types to be stored [1].
    3. ... under one identifier [1].

    Trap: 'An array' on its own earns nothing: an array holds one data type.

  5. Write pseudocode to declare a record type Book with these fields: Title (a string), Pages (an integer), Price (a price in pounds and pence) and OnLoan (a Boolean).4 marks
    Answer
    1. ``` TYPE Book DECLARE Title : STRING DECLARE Pages : INTEGER DECLARE Price : REAL DECLARE OnLoan : BOOLEAN ENDTYPE ```
    2. One mark each: `TYPE` and `ENDTYPE` [1]; Title and Pages [1]; Price as `REAL` [1]; OnLoan as `BOOLEAN` [1].

    Trap: A price with pence is `REAL`, because an `INTEGER` price loses the pence.

  6. Write pseudocode to declare a 1D array Library to hold 800 Book records.2 marks
    Answer
    1. ``` DECLARE Library : ARRAY [1:800] OF Book ```
    2. Array of type `Book` [1]; bounds that give 800 elements [1].

    Trap: `ARRAY [0:800]` has 801 elements, so the bounds must be `[1:800]` or `[0:799]`.

  7. A variable MyBook of type Book has been declared. Write pseudocode to store the string "Dune" in its Title field and the value TRUE in its OnLoan field.2 marks
    Answer
    1. ``` MyBook.Title ← "Dune" MyBook.OnLoan ← TRUE ```
    2. One mark for each assignment [1] [1].

    Trap: `Book.Title` uses the type name and `MyBook:Title` uses a colon, so write the variable, a dot, then the field.

  8. Library[3] holds a Book record. Write pseudocode to output its Title, and to output "On loan" only if its OnLoan field is TRUE.3 marks
    Answer
    1. ``` OUTPUT Library[3].Title IF Library[3].OnLoan = TRUE THEN OUTPUT "On loan" ENDIF ```
    2. One mark each: the Title output [1]; the `IF` test on OnLoan [1]; the conditional output with `ENDIF` [1].

    Trap: `Library.Title[3]` puts the index after the field, but the index belongs to the array and comes before the dot.

  9. A car park stores each visit in a record of type Visit with the fields Reg (a string), Entry (a date), Minutes (an integer), Paid (a Boolean) and Fee (a fee in pounds and pence). Visits is a global 1D array of 300 Visit records. A visit that is unused has Minutes set to -1. Write pseudocode for a procedure UnpaidTotal() that outputs the number of visits not yet paid and the total of their fees.6 marks
    Answer
    1. Procedure heading and ending; `Total` declared as `REAL` and `Count` as `INTEGER`, both set to 0 [1].
    2. Loop through all 300 elements [1].
    3. Skip an unused visit: `Visits[Index].Minutes <> -1` [1].
    4. Test `Visits[Index].Paid = FALSE` [1].
    5. Add `Visits[Index].Fee` to `Total` and add 1 to `Count` [1].
    6. Output `Count` and `Total` after the loop [1].
    7. ``` PROCEDURE UnpaidTotal() DECLARE Index, Count : INTEGER DECLARE Total : REAL Count ← 0 Total ← 0 FOR Index ← 1 TO 300 IF Visits[Index].Minutes <> -1 THEN IF Visits[Index].Paid = FALSE THEN Total ← Total + Visits[Index].Fee Count ← Count + 1 ENDIF ENDIF NEXT Index OUTPUT Count, Total ENDPROCEDURE ```

    Trap: Examiners often found a count not initialised before the loop, so set `Count` and `Total` to 0 first and make `Total` `REAL` to keep the pence.

  10. A car park stores each visit in a record of type Visit with the fields Reg (a string), Entry (a date), Minutes (an integer), Paid (a Boolean) and Fee (a fee in pounds and pence). Visits is a global 1D array of 300 Visit records. A visit that is unused has Minutes set to -1. Write pseudocode for a procedure AddVisit() that takes a registration and a date as parameters. It stores a new visit in the first unused element only, with Reg and Entry from the parameters, Minutes 0, Paid FALSE and Fee 0. If no element is unused, it outputs "Car park full".6 marks
    Answer
    1. Procedure heading with two parameters of type `STRING` and `DATE`, and `ENDPROCEDURE` [1].
    2. A conditional loop from element 1 that stops at the first unused element or after element 300 [1].
    3. Test for an unused element: `Visits[Index].Minutes = -1` [1].
    4. Save the parameters: `Visits[Index].Reg ← NewReg` and `Visits[Index].Entry ← Today` [1].
    5. Save `Minutes` 0, `Paid` FALSE and `Fee` 0, so the element is now in use [1].
    6. Output "Car park full" after the loop only if no unused element was found [1].
    7. ``` PROCEDURE AddVisit(NewReg : STRING, Today : DATE) DECLARE Index : INTEGER DECLARE Found : BOOLEAN Found ← FALSE Index ← 1 WHILE Found = FALSE AND Index <= 300 IF Visits[Index].Minutes = -1 THEN Visits[Index].Reg ← NewReg Visits[Index].Entry ← Today Visits[Index].Minutes ← 0 Visits[Index].Paid ← FALSE Visits[Index].Fee ← 0 Found ← TRUE ENDIF Index ← Index + 1 ENDWHILE IF Found = FALSE THEN OUTPUT "Car park full" ENDIF ENDPROCEDURE ```

    Trap: Examiners report candidates replacing parameters with prompts and inputs inside the subroutine and using a FOR loop that does not stop when the item is added, so use NewReg and Today and a conditional loop.

Say this, not that

Wording that loses the mark, against the wording the mark scheme credits.

Loses the markGets the mark
`Date` or 'flag' as a variable namea meaningful name such as StartDate or FamilyMember
'an array', 'a database' or 'a file'a record
a record holds different data typesa record holds different data types under one identifier
`StockItem.Cost ← 12.99``LineData.Cost ← 12.99`: the record variable, a dot, then the field

Frequently asked questions

Which data type should I use for a value like 15.75 or the letter S in pseudocode?
Use REAL for a number with a decimal part, such as 15.75, and CHAR for a single letter, such as 'S'. A whole number such as 1345 is INTEGER. Text, or a code with letters and numbers such as "1B", is STRING. TRUE or FALSE is BOOLEAN, and a calendar value such as 19/02/1983 is DATE.
Why is a record the right data structure when items have different data types?
A record holds a set of data of different data types under one identifier. An array holds items of one data type, so it cannot suit a mix. Saying only 'an array', 'a database' or 'a file' earns no mark. The justification must name both different data types and one identifier.
How do you declare a record type and an array of records in pseudocode?
Declare the record between TYPE and ENDTYPE, with one DECLARE line for each field, giving its name and data type. Then declare the array with the record as its element type, for example DECLARE Item : ARRAY [1:2000] OF Component. The bounds [1:2000] give 2000 elements.
How do you access a field in a record variable?
Use dot notation: the record variable, a dot, then the field name, as in LineData.Cost ← 12.99. In an array of records the index comes first, as in Staff[Index].Attendance. Writing Library.Title[3] puts the index after the field, which is wrong.
How do I mark an unused record in an array of records?
Set one field to an impossible value, such as an EmployeeNumber below 1, or Minutes to -1 in the car park example. Then test that field before using the record, and skip the element when processing the array. Some records in the array may be unused, so the test is needed.
Why is Date a poor variable name in pseudocode?
Date is the name of a data type, so it is a keyword and cannot be used as a variable name. Names such as flag or name are also too imprecise. Use a meaningful name that says what the variable stores, such as StartDate with the type DATE.

Free notes are just the start.

Unlock every Workbook and Chapter at a Glance, and generate your own worksheets and predicted papers.

Explore plans

Related chapters