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

Q30 · 9618/32/M/J/25 Q13

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

Q309618/32/M/J/25original Q13Structured · 5 marks
Question 13 from 9618/32/M/J/25

Worked solution

Open the live file too. Loop through the 50 records, add the text if the grade is missing, then SEEK in the stored file and write the record.

DECLARE Grade : StudentResult
DECLARE Position : INTEGER
OPENFILE "CurrentResults.dat" FOR RANDOM
OPENFILE "StoredResults.dat" FOR RANDOM
FOR Position ← 1 TO 50
    SEEK "CurrentResults.dat", Position
    GETRECORD "CurrentResults.dat", Grade
    IF Grade.ExamGrade = "" THEN
        Grade.ExamGrade ← "Missing grade"
    ENDIF
    SEEK "StoredResults.dat", Position
    PUTRECORD "StoredResults.dat", Grade
NEXT Position
CLOSEFILE "CurrentResults.dat"
CLOSEFILE "StoredResults.dat"

OPENFILE "CurrentResults.dat" FOR RANDOM [1]

FOR Position ← 1 TO 50 [1]

Grade.ExamGrade ← "Missing grade" inside the IF [1]

SEEK "StoredResults.dat", Position [1]

PUTRECORD "StoredResults.dat", Grade [1]

KEY IDEAWith random files, SEEK to the record position before each GETRECORD or PUTRECORD.
TOTAL 5 marks

Official mark scheme

Mark scheme for 9618/32/M/J/25 question 13
VIDEO
▶ Topic lesson

A lesson on this topic · by James Gan. 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.