9618/31/O/N/23 question 8: worked solution (October/November 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. Q27 9618/31/O/N/23 original Q8 Structured · 8 marks Worked solution (a) Fill each gap in order. The record is found with its hash value, so SEEK goes to that location and GETRECORD reads it. AccountFile ← "AccountRecords.dat" OPENFILE AccountFile FOR RANDOM OUTPUT "Please enter an account number" INPUT Customer.AccountNumber Location ← Hash(Customer.AccountNumber) SEEK AccountFile, Location GETRECORD AccountFile, Customer OUTPUT Customer // output customer record CLOSEFILE AccountFile First gap: AccountFile [1] Second line: OPENFILE and FOR RANDOM [1] Hash parameter: Customer.AccountNumber [1] SEEK gap: AccountFile [1] Last gap: GETRECORD before AccountFile and Customer after it [1] (b) Write: Exception handling is responding to an unexpected event while the program is running, so that the program does not stop (crash) unexpectedly. [1] (c) Write any two causes: A programming error , for example dividing by zero. [1] A user error , for example typing a wrong file name. [1] Other accepted causes: hardware failure or a runtime error . KEY IDEA Random-file access goes OPENFILE FOR RANDOM, SEEK to the record's location, GETRECORD, then CLOSEFILE; exception handling stops unexpected events from crashing the program. TOTAL 8 marks Official mark scheme VIDEO ▶ Topic lesson A lesson on this topic · by James Gan. Tap the picture to open it on YouTube.