9618/33/M/J/25 question 11: worked solution (May/June 2025, paper 33)

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. Q31 9618/33/M/J/25 original Q11 Structured · 5 marks Worked solution Open the file first. In the loop, SEEK to the location, read the record, and write the new item if the location is empty. After the loop, report if nothing was stored. OPENFILE "StockList.dat" FOR RANDOM OUTPUT "Enter the new item you wish to store: " INPUT NewStock WHILE NOT Stored AND Location <= Max SEEK "StockList.dat", Location GETRECORD "StockList.dat", CurrentStock IF CurrentStock = "" THEN PUTRECORD "StockList.dat", NewStock Stored ← TRUE ELSE Location ← Location + 1 ENDIF ENDWHILE IF Stored = FALSE THEN OUTPUT "The new item has not been stored as the file was full." ENDIF CLOSEFILE "StockList.dat" OPENFILE "StockList.dat" FOR RANDOM [1] SEEK "StockList.dat", Location [1] GETRECORD "StockList.dat", CurrentStock [1] PUTRECORD "StockList.dat", NewStock [1] IF Stored = FALSE THEN (NOT Stored is also fine) [1] KEY IDEA Open the random file, SEEK then GETRECORD to test each location, and PUTRECORD at the first empty one. 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.