Using records

Using Records

A record is a data structure that groups a fixed set of related values - called fields - that describe a single entity. Unlike an array, whose elements must all share the same data type, a record can combine fields of different types. For example, a student record might hold a name (string), an age (integer), and an average score (real) all together in one structure.

Records are used whenever a program needs to represent one complete "thing" - a student, a book in a library, a product in a shop - where each attribute of that thing has its own name and type.

AQA RECORD Syntax

AQA pseudocode defines a record type using the RECORD and ENDRECORD keywords. Each line inside declares one field with its name and data type. Once defined, you create a variable of that type and access fields using dot notation.

RECORD Student
    name    : String
    age     : Integer
    score   : Real
ENDRECORD

s ← NEW Student
s.name  ← "Alice"
s.age   ← 15
s.score ← 88.5
OUTPUT s.name + " aged " + s.age + " scored " + s.score

In real programming languages, the record concept is implemented differently in each language - the table below summarises the equivalents you need to know.

LanguageRecord equivalentField access
AQA pseudocodeRECORD...ENDRECORDDot notation: s.name
PythonA class with __init__Dot notation: s.name
VB.NETStructure...End StructureDot notation: s.name
C#struct { }Dot notation: s.name

Records in Practice

The examples below show two different real-world records. Select a tab to explore each context, then select a language to see the implementation.

A student record holds four fields of different types: name (String), age (Integer), average score (Real), and whether they are enrolled (Boolean). The program creates a student, fills the fields, and prints a summary.

AQA pseudocode:

RECORD Student
    name     : String
    age      : Integer
    avgScore : Real
    enrolled : Boolean
ENDRECORD

s ← NEW Student
s.name     ← "Alice"
s.age      ← 15
s.avgScore ← 88.5
s.enrolled ← TRUE
OUTPUT s.name + " | Age: " + s.age + " | Score: " + s.avgScore
# Python -- class used as record equivalent
class Student:
    def __init__(self, name, age, avg_score, enrolled):
        self.name      = name        # String
        self.age       = age         # Integer
        self.avg_score = avg_score   # Real (float)
        self.enrolled  = enrolled    # Boolean

# Create a Student record and assign field values
s = Student("Alice", 15, 88.5, True)

# Access fields using dot notation
print(s.name + " | Age:", s.age, "| Score:", s.avg_score)
print("Enrolled:", s.enrolled)
' VB.NET -- Structure used as record equivalent
Structure Student
    Dim name     As String
    Dim age      As Integer
    Dim avgScore As Double
    Dim enrolled As Boolean
End Structure

' Create a Student variable and assign field values
Dim s As Student
s.name     = "Alice"
s.age      = 15
s.avgScore = 88.5
s.enrolled = True

' Access fields using dot notation
Console.WriteLine(s.name & " | Age: " & s.age & " | Score: " & s.avgScore)
Console.WriteLine("Enrolled: " & s.enrolled)
// C# -- struct used as record equivalent
struct Student
{
    public string name;
    public int    age;
    public double avgScore;
    public bool   enrolled;
}

// Create a Student variable and assign field values
Student s;
s.name     = "Alice";
s.age      = 15;
s.avgScore = 88.5;
s.enrolled = true;

// Access fields using dot notation
Console.WriteLine(s.name + " | Age: " + s.age + " | Score: " + s.avgScore);
Console.WriteLine("Enrolled: " + s.enrolled);

A library book record holds five fields: title, author (both String), year published (Integer), price (Real), and whether it is currently available (Boolean). The program creates a book record, then checks availability before printing loan information.

AQA pseudocode:

RECORD Book
    title     : String
    author    : String
    yearPub   : Integer
    price     : Real
    available : Boolean
ENDRECORD

b ← NEW Book
b.title     ← "Ender's Game"
b.author    ← "Orson Scott Card"
b.yearPub   ← 1985
b.price     ← 7.99
b.available ← TRUE

IF b.available = TRUE THEN
    OUTPUT b.title + " by " + b.author + " is available to borrow."
ELSE
    OUTPUT b.title + " is currently on loan."
ENDIF
# Python -- Book record
class Book:
    def __init__(self, title, author, year_pub, price, available):
        self.title     = title       # String
        self.author    = author      # String
        self.year_pub  = year_pub    # Integer
        self.price     = price       # Real (float)
        self.available = available   # Boolean

b = Book("Ender's Game", "Orson Scott Card", 1985, 7.99, True)

if b.available:
    print(b.title + " by " + b.author + " is available to borrow.")
else:
    print(b.title + " is currently on loan.")
' VB.NET -- Book record
Structure Book
    Dim title     As String
    Dim author    As String
    Dim yearPub   As Integer
    Dim price     As Double
    Dim available As Boolean
End Structure

Dim b As Book
b.title     = "Ender's Game"
b.author    = "Orson Scott Card"
b.yearPub   = 1985
b.price     = 7.99
b.available = True

If b.available Then
    Console.WriteLine(b.title & " by " & b.author & " is available to borrow.")
Else
    Console.WriteLine(b.title & " is currently on loan.")
End If
// C# -- Book record
struct Book
{
    public string title;
    public string author;
    public int    yearPub;
    public double price;
    public bool   available;
}

Book b;
b.title     = "Ender's Game";
b.author    = "Orson Scott Card";
b.yearPub   = 1985;
b.price     = 7.99;
b.available = true;

if (b.available)
    Console.WriteLine(b.title + " by " + b.author + " is available to borrow.");
else
    Console.WriteLine(b.title + " is currently on loan.");

 Key Takeaways

  • A record groups a fixed set of named fields that describe one entity. Each field can have a different data type.
  • AQA pseudocode uses RECORD...ENDRECORD. Python uses a class, VB.NET uses a Structure, and C# uses a struct.
  • Fields are accessed using dot notation: variable.fieldName - the same syntax in all three languages and in AQA pseudocode.
  • Unlike an array (same type for every element), a record is specifically designed to mix field types - strings, integers, reals, and Booleans can all coexist in one record.
  • Records are most useful when a program needs to store all the attributes of one real-world entity together, making the code more organised and readable.