9618/31/M/J/25 question 12: worked solution (May/June 2025, 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. Q29 9618/31/M/J/25 original Q12 Structured · 5 marks Worked solution (a) 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] KEY IDEA Open a random file, SEEK to the location the user gave, GETRECORD into a variable, and CLOSEFILE when finished. TOTAL 5 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by James Gan. Tap the picture to open it on YouTube.