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

Q27 · 9618/31/O/N/23 Q8

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

Q279618/31/O/N/23original Q8Structured · 8 marks
Question 8 from 9618/31/O/N/23

Worked solution

(a)

Fill each gap in order. The record is found with its hash value, so SEEK goes to that location and GETRECORD reads it.

AccountFile ← "AccountRecords.dat"
OPENFILE AccountFile FOR RANDOM
OUTPUT "Please enter an account number"
INPUT Customer.AccountNumber
Location ← Hash(Customer.AccountNumber)
SEEK AccountFile, Location
GETRECORD AccountFile, Customer
OUTPUT Customer // output customer record
CLOSEFILE AccountFile

First gap: AccountFile [1]

Second line: OPENFILE and FOR RANDOM [1]

Hash parameter: Customer.AccountNumber [1]

SEEK gap: AccountFile [1]

Last gap: GETRECORD before AccountFile and Customer after it [1]

(b)

Write: Exception handling is responding to an unexpected event while the program is running, so that the program does not stop (crash) unexpectedly. [1]

(c)

Write any two causes:

A programming error, for example dividing by zero. [1]

A user error, for example typing a wrong file name. [1]

Other accepted causes: hardware failure or a runtime error.

KEY IDEARandom-file access goes OPENFILE FOR RANDOM, SEEK to the record's location, GETRECORD, then CLOSEFILE; exception handling stops unexpected events from crashing the program.
TOTAL 8 marks

Official mark scheme

Mark scheme for 9618/31/O/N/23 question 8
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.