9618/23/O/N/24 question 4: worked solution (October/November 2024, paper 23)

Show as plain text

Cambridge AS Level Computer Science 9618 · 10.2 Arrays Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 2 of 4. Q34 9618/23/O/N/24 original Q4 Structured · 12 marks Worked solution (a) There are five grade boundaries. Upper is the boundary plus 2. The mark is within range if it is at least Lower and at most Upper. FOR Index ← 1 TO 5 Lower ← GB[Index] - 2 Upper ← GB[Index] + 2 IF Mark >= Lower AND Mark <= Upper THEN OUTPUT "Check this paper" ENDIF NEXT Index 5 [1] GB[Index] + 2 (or Lower + 4) [1] >= Lower [1] <= Upper [1] (b)(i) Use the mark as an index. Use Mark as the index of the Check array [1] If that element is TRUE , the paper must be checked [1] (b)(ii) Set every element to FALSE first. Then for each boundary set the five elements from boundary - 2 to boundary + 2 to TRUE. PROCEDURE GBInitialise() DECLARE GBIndex, GBMark, ThisIndex : INTEGER FOR ThisIndex ← 0 TO 75 Check[ThisIndex] ← FALSE NEXT ThisIndex FOR GBIndex ← 1 TO 5 GBMark ← GB[GBIndex] FOR ThisIndex ← GBMark - 2 TO GBMark + 2 Check[ThisIndex] ← TRUE NEXT ThisIndex NEXT GBIndex ENDPROCEDURE Procedure heading and ENDPROCEDURE [1] All elements of Check set to FALSE first [1] Loop through the GB array [1] Boundary mark taken from GB [1] Loop over the five marks from boundary - 2 to boundary + 2 [1] Each of those Check elements set to TRUE [1] Another way that scores: loop 0 to 75 and test each index against all five boundaries, setting TRUE or FALSE. KEY IDEA A lookup array of TRUE/FALSE flags indexed by mark replaces repeated range checks. TOTAL 12 marks Official mark scheme VIDEO ▶ Whole paper Video solution of the whole paper · by Zafar Ali Khan (ZAK). Tap the picture to open it on YouTube.