9618/23/M/J/24 question 2: worked solution (May/June 2024, paper 23)
Show as plain textHide plain text
Cambridge AS Level Computer Science 9618 · 9.2 Algorithms Worked solution from the Algorithm Design and Problem-solving Paper 2 Problem-solving and Programming booklet, Part 2 of 2. Q37 9618/23/M/J/24 original Q2 Structured · 7 marks Worked solution (a) Write five steps in words (no pseudocode): Open the file for reading (and close it at the end) [1] Set an index variable to 1 [1] Repeat the next steps until the end of the file is reached [1] Read a line from the file [1] Store that line in the array at the index, and add 1 to the index [1] There are six possible points; any five score. (b) Construct: a conditional loop (iteration) [1] Use: to keep repeating until the end of the file is reached [1] Alternative: a selection statement used to test the value returned by EOF() (also scores both marks if the use is given). KEY IDEA Reading a file into an array needs a loop that runs until the end of the file with an index that moves on each time. TOTAL 7 marks Official mark scheme VIDEO ▶ Starts at Q2 (10:33) Starts at Q2 (10:33) · by Pseudocode Pro. Tap the picture to open it on YouTube.