9618/32/O/N/23 question 12: worked solution (October/November 2023, paper 32)

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. Q28 9618/32/O/N/23 original Q12 Structured · 9 marks Worked solution (a) Write: an exception is an event during a program's run that disrupts the normal flow of instructions or makes the program stop. [1] Give an example, such as a hardware failure (disk crash), a divide by zero or out-of-range array index, or a user error like a wrong file name. [1] (b) Fill each gap. The loop stops when the customer is found or the end of the file is reached. OPENFILE "AccountRecord.dat" FOR RANDOM Location ← 1 FoundFlag ← FALSE OUTPUT "Enter the customer’s name" INPUT SearchCustomer WHILE NOT FoundFlag AND Location <= MaxSize SEEK "AccountRecord.dat", Location GETRECORD "AccountRecord.dat", Customer IF SearchCustomer = Customer.Name THEN OUTPUT "Customer found: " OUTPUT Customer // output customer record FoundFlag ← TRUE ENDIF Location ← Location + 1 ENDWHILE IF NOT FoundFlag THEN OUTPUT "Customer does not exist." ENDIF OPENFILE gap: "AccountRecord.dat" FOR RANDOM [1] Flag gap: FoundFlag [1] Input line: INPUT SearchCustomer [1] WHILE gap: WHILE NOT FoundFlag [1] SEEK gap: SEEK [1] Position gap: Location [1] Error message, such as Customer does not exist. [1] KEY IDEA Search a random file with a WHILE loop that stops when the item is found or the last location is passed. TOTAL 9 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by TEACHING BY SM. Tap the picture to open it on YouTube.