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

Q29 · 9618/31/M/J/25 Q12

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

Q299618/31/M/J/25original Q12Structured · 5 marks
Question 12 from 9618/31/M/J/25

Worked solution

(a)

Fill each gap using the random-file commands.

OPENFILE "StockList.dat" FOR RANDOM
WHILE Continue
    OUTPUT "Enter a location between 1 and 500: "
    INPUT Location
    SEEK "StockList.dat", Location
    GETRECORD "StockList.dat", Item
    IF Item = "" THEN
        OUTPUT "This record is missing."
    ELSE
        OUTPUT "The item in stock is ", Item
    ENDIF
    OUTPUT "Another location (Y or N)?"
    INPUT Answer
    IF Answer <> 'Y' THEN
        Continue ← FALSE
    ENDIF
ENDWHILE
CLOSEFILE "StockList.dat"
OUTPUT "End of program"

OPENFILE gap: "StockList.dat" FOR RANDOM [1]

Line before GETRECORD: SEEK "StockList.dat", Location [1]

GETRECORD gap: "StockList.dat", Item [1]

Output gap: Item [1]

After the loop: CLOSEFILE "StockList.dat" [1]

KEY IDEAOpen a random file, SEEK to the location the user gave, GETRECORD into a variable, and CLOSEFILE when finished.
TOTAL 5 marks

Official mark scheme

Mark scheme for 9618/31/M/J/25 question 12
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.