Worked solution from the Further Programming Paper 3 Advanced Theory booklet, Part 2 of 2.
Open the active file for reading, loop until its end, write the right text, then close both files.
DECLARE Account : STRING
OPENFILE "ActiveFile.txt" FOR READ
OPENFILE "ArchiveFile.txt" FOR WRITE
WHILE NOT EOF("ActiveFile.txt")
READFILE "ActiveFile.txt", Account
IF Account = "" THEN
WRITEFILE "ArchiveFile.txt", "Account not present"
ELSE
WRITEFILE "ArchiveFile.txt", Account
ENDIF
ENDWHILE
CLOSEFILE "ActiveFile.txt"
CLOSEFILE "ArchiveFile.txt"OPENFILE "ActiveFile.txt" FOR READ [1]
EOF("ActiveFile.txt") as the loop condition [1]
"Account not present" written for a blank line [1]
Account written in the ELSE part [1]
CLOSEFILE "ActiveFile.txt" after the loop [1]
▶ Whole paper
Video solution of the whole paper · by qiphyedu. 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.