Fields, records and files — AQA A-Level Computer Science
In AQA A-Level Computer Science, a field represents a single data item, a record is an ordered collection of related fields representing an entity, and a file stores a collection of records. Mastering these fundamentals is essential for understanding secondary storage management, data serialisation, and database architecture.
Fields, records and files explained
Reading and writing a text file means a program transfers data between memory and a file stored on secondary storage, using a file handle that the program opens, uses and closes.
Read the full explanation
A text file stores characters as human-readable encoded values, usually one record per line, so a program reads it line by line or character by character and writes it by sending strings to the file. When reading, the program opens the file in read mode, retrieves each line until the end of file is reached, and then closes the file. When writing, the program opens the file in write mode, which normally creates or overwrites the file, or in append mode, which adds to the end of existing content, then sends each string and closes the file. Because the data is stored as characters, numbers read from the file are strings and must be converted before arithmetic is performed on them.
Your focus
- Be able to read/write from/to a text file.
Which command word is this?
Set out the causes, reasons, or mechanisms clearly using accurate technical language (e.g. explaining why fixed-length records allow direct addressing).
Fields, records and files exam tips
Topic Overview
Data organisation is a foundational concept in computer science that bridges the gap between high-level programmatic data structures and physical secondary storage. This topic examines the data hierarchy: individual fields combining into records, which in turn are aggregated into files stored on disk.
Understanding the mechanics of records and files is essential for software development, system design, and database normalisation. It enables students to evaluate trade-offs between memory overhead, disk input/output performance, and algorithmic search efficiency in AQA A-Level Computer Science.
Key Concepts
- →Hierarchical data structure: Characters form fields (attributes), fields form records (tuples), and records form files (tables).
- →Record heterogeneity: Unlike standard arrays which are homogeneous, records can contain elements of disparate data types (e.g. strings, integers, booleans).
- →Fixed vs Variable Length Records: Fixed-length simplifies byte-offset direct addressing at the cost of internal fragmentation, whereas variable-length optimises capacity using end-of-record delimiters or length-prefix bytes.
- →File Organisation vs File Access: File organisation defines how records are physically stored on storage media (serial, sequential, indexed sequential, or direct/random), while file access dictates the mechanism used to retrieve them.
Marking Points
- Opens the file in the correct mode for the operation, such as read, write or append
- Reads data line by line or character by character until end of file is detected
- Writes strings to the file and recognises that numbers must be converted to strings first
- Converts values read from the file back to numbers before performing arithmetic
- Closes the file after use to release the file handle and ensure data is saved
Examiner Tips
- 💡Trace the code line by line, noting the mode in each open statement
- 💡Check whether a value read from the file is a string before using it in arithmetic
- 💡State the effect of the open mode when a question asks what will happen to existing data
- 💡Always state the primary key or key field when explaining how records are uniquely identified and searched in sequential and indexed-sequential files.
- 💡When explaining how an operating system reads a fixed-length record directly, always explicitly reference the term 'byte offset' or show the calculation: address = record_number * record_length.
- 💡Remember that variable-length records require end-of-record markers (such as carriage return/line feed) or field-length indicators so the file pointer knows where one record terminates and the next begins.
Common Mistakes
- Treats a text file as holding numeric values directly; the values are stored as characters and must be converted
- Opens a file in write mode when the intended operation is to add data, which overwrites existing content; use append mode instead
- Omits the close step, which may leave written data unsaved or the file locked
- Believing records and arrays are interchangeable: Arrays require identical data types across elements, whereas records deliberately bind heterogeneous fields representing an entity under one identifier.
- Assuming binary conversion factors equal 1000: When calculating file sizes for AQA assessments, KiB and MiB use binary powers (1024 and 1024^2), not decimal SI units (1000), unless explicitly instructed.
- Confusing serial files with sequential files: A serial file stores records chronologically as they arrive without an ordering key, while a sequential file stores records logically ordered by a designated primary/key field.
Revision Plan
- 1Day 1-2: Master core terminology. Draw and annotate diagrams depicting a field, record, file, and primary key using clear entity examples.
- 2Day 3-5: Practice file size calculation problems involving fixed-length records, ensuring accurate byte summation and conversion into KiB/MiB.
- 3Day 6-8: Compare and contrast file organisations (serial, sequential, indexed sequential, and random/hashed), creating a comparison matrix of their time complexities for insertion, deletion, and searching.
- 4Day 9-10: Work through past paper questions focusing on the trade-offs between fixed-length and variable-length record architectures.
Exam Question Types
- 📋Calculation questions: Determining total file or record size in bytes, KiB, or MiB given individual field constraints and record totals.
- 📋Comparative structure questions: Contrasting fixed-length records with variable-length records, or arrays with user-defined record structures.
- 📋File organisation scenario questions: Evaluating whether serial, sequential, or direct access is most appropriate for a given real-world application (e.g. batch payroll vs online booking).
Command Word Expectations (AQA)
Set out the causes, reasons, or mechanisms clearly using accurate technical language (e.g. explaining why fixed-length records allow direct addressing).
Perform mathematical operations showing full step-by-step working out, correctly using binary multipliers (1024) where relevant, and including appropriate units (e.g. bytes, KiB).
Identify both similarities and differences between two concepts (e.g. sequential access vs random access), explicitly addressing both items rather than just defining them in isolation.
How Students Lose Marks (Examiner Pitfalls)
Step-by-Step Worked Solutions
Question: A school creates a customer file using fixed-length records. Each record consists of: StudentID (6 bytes, ASCII string), Forename (15 bytes, ASCII string), Surname (20 bytes, ASCII string), DateOfBirth (8 bytes, Date format), and YearGroup (1 byte, Integer). Calculate the total file size in kibibytes (KiB) if the file contains 1,200 student records. Show all workings.
- 1.Step 1: Calculate the size of a single record by summing the bytes of each field: 6 (StudentID) + 15 (Forename) + 20 (Surname) + 8 (DateOfBirth) + 1 (YearGroup) = 50 bytes per record.
- 2.Step 2: Calculate the total raw data size in bytes for 1,200 records: 1,200 records * 50 bytes = 60,000 bytes.
- 3.Step 3: Convert bytes to kibibytes (KiB) by dividing by 1,024: 60,000 / 1,024 = 58.59375 KiB.
Question: A direct access file stores fixed-length customer records of exactly 128 bytes each. The first record (Record 0) begins at physical byte position 0. Outline the mathematical formula used to calculate the starting byte address of Record n, and calculate the exact starting byte address of Record 45.
- 1.Step 1: Identify the standard random access offset formula: Starting Address = Base Address + (Record Index * Record Length).
- 2.Step 2: Substitute the known values: Base Address = 0, Record Length = 128 bytes, Record Index = 45.
- 3.Step 3: Calculate the memory byte offset: Address = 0 + (45 * 128) = 5,760.