Worked solution from the Further Programming Paper 3 Advanced Theory booklet, Part 2 of 2.
Write: an exception is an event during a program's run that disrupts the normal flow of instructions or makes the program stop. [1]
Give an example, such as a hardware failure (disk crash), a divide by zero or out-of-range array index, or a user error like a wrong file name. [1]
Fill each gap. The loop stops when the customer is found or the end of the file is reached.
OPENFILE "AccountRecord.dat" FOR RANDOM
Location ← 1
FoundFlag ← FALSE
OUTPUT "Enter the customer’s name"
INPUT SearchCustomer
WHILE NOT FoundFlag AND Location <= MaxSize
SEEK "AccountRecord.dat", Location
GETRECORD "AccountRecord.dat", Customer
IF SearchCustomer = Customer.Name THEN
OUTPUT "Customer found: "
OUTPUT Customer // output customer record
FoundFlag ← TRUE
ENDIF
Location ← Location + 1
ENDWHILE
IF NOT FoundFlag THEN
OUTPUT "Customer does not exist."
ENDIFOPENFILE gap: "AccountRecord.dat" FOR RANDOM [1]
Flag gap: FoundFlag [1]
Input line: INPUT SearchCustomer [1]
WHILE gap: WHILE NOT FoundFlag [1]
SEEK gap: SEEK [1]
Position gap: Location [1]
Error message, such as Customer does not exist. [1]
▶ Whole paper
Video solution of the whole paper · by TEACHING BY SM. 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.