9618/31/M/J/23 question 10: worked solution (May/June 2023, paper 31)

Show as plain text

Cambridge A2 Level Computer Science 9618 · 20.2 File Processing and Exception Handling Worked solution from the Further Programming Paper 3 Advanced Theory booklet, Part 2 of 2. Q25 9618/31/M/J/23 original Q10 Structured · 5 marks Worked solution 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] KEY IDEA Open each file with the right mode, loop until EOF, read and write one line at a time, then close every file. TOTAL 5 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by qiphyedu. Tap the picture to open it on YouTube.