Worked solution from the Further Programming Paper 3 Advanced Theory booklet, Part 2 of 2.
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]
▶ 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.