Cambridge A2 Level Computer Science 9618 · 20.2 File Processing and Exception Handling

Q26 · 9618/32/M/J/23 Q6

Worked solution from the Further Programming Paper 3 Advanced Theory booklet, Part 2 of 2.

Q269618/32/M/J/23original Q6Structured · 9 marks
Question 6 from 9618/32/M/J/23

Worked solution

(a)

A composite type starts with TYPE and ends with ENDTYPE. Inside, declare one field for each item of data. Dates use DATE, yes/no uses BOOLEAN and a telephone number is a STRING (it can start with 0).

TYPE TAppointments
    DECLARE FirstName : STRING
    DECLARE LastName : STRING
    DECLARE DateOfBirth : DATE
    DECLARE Telephone : STRING
    DECLARE LastAppointment : DATE
    DECLARE NextAppointment : DATE
    DECLARE TreatmentsComplete : BOOLEAN
ENDTYPE

TYPE TAppointments and ENDTYPE correct [1]

Two correct declarations (for example the name fields) [1]

Two more correct declarations (for example the dates) [1]

Two more correct declarations (for example Telephone and TreatmentsComplete) [1]

A single Name field is also accepted.

(b)

Fill each gap using the random-file commands: OPENFILE ... FOR RANDOM, SEEK, GETRECORD, EOF and CLOSEFILE.

OPENFILE DentalFile FOR RANDOM
Count ← 1
REPEAT
    SEEK DentalFile, Count
    GETRECORD DentalFile, DentalRecord[Count]
    OUTPUT DentalRecord[Count]
    Count ← Count + 1
UNTIL EOF(DentalFile)
CLOSEFILE DentalFile

Write DentalFile FOR RANDOM after OPENFILE [1]

Write Count before ← 1 [1]

Write GETRECORD DentalFile, DentalRecord[Count] after SEEK [1]

Write UNTIL EOF before (DentalFile) [1]

Write CLOSEFILE DentalFile on the last line [1]

KEY IDEAIn a random file, open it FOR RANDOM, SEEK a position, then GETRECORD into a variable, and CLOSEFILE at the end.
TOTAL 9 marks

Official mark scheme

Mark scheme for 9618/32/M/J/23 question 6
VIDEO
▶ Whole paper

Video solution of the whole paper · by qiphyedu. Tap the picture to open it on YouTube.

Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.