9618/32/M/J/23 question 6: worked solution (May/June 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. Q26 9618/32/M/J/23 original Q6 Structured · 9 marks Worked solution (a) A composite type starts with TYPE and ends with ENDTYPE. Inside, declare one field for each item of data. Dates use DATE, yes/no uses BOOLEAN and a telephone number is a STRING (it can start with 0). TYPE TAppointments DECLARE FirstName : STRING DECLARE LastName : STRING DECLARE DateOfBirth : DATE DECLARE Telephone : STRING DECLARE LastAppointment : DATE DECLARE NextAppointment : DATE DECLARE TreatmentsComplete : BOOLEAN ENDTYPE TYPE TAppointments and ENDTYPE correct [1] Two correct declarations (for example the name fields) [1] Two more correct declarations (for example the dates) [1] Two more correct declarations (for example Telephone and TreatmentsComplete) [1] A single Name field is also accepted. (b) Fill each gap using the random-file commands: OPENFILE ... FOR RANDOM, SEEK, GETRECORD, EOF and CLOSEFILE. OPENFILE DentalFile FOR RANDOM Count ← 1 REPEAT SEEK DentalFile, Count GETRECORD DentalFile, DentalRecord[Count] OUTPUT DentalRecord[Count] Count ← Count + 1 UNTIL EOF(DentalFile) CLOSEFILE DentalFile Write DentalFile FOR RANDOM after OPENFILE [1] Write Count before ← 1 [1] Write GETRECORD DentalFile, DentalRecord[Count] after SEEK [1] Write UNTIL EOF before (DentalFile) [1] Write CLOSEFILE DentalFile on the last line [1] KEY IDEA In a random file, open it FOR RANDOM, SEEK a position, then GETRECORD into a variable, and CLOSEFILE at the end. TOTAL 9 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by qiphyedu. Tap the picture to open it on YouTube.