9618/22/M/J/23 question 2: worked solution (May/June 2023, paper 22)

Show as plain text

Cambridge AS Level Computer Science 9618 · 11.1 Programming Basics Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 1 of 3. Q11 9618/22/M/J/23 original Q2 Structured · 9 marks Worked solution (a) Use the SETDATE function from the insert: MyDOB ← SETDATE(17, 11, 2007) Correct statement [1] (b) Months left in the year are 12 minus the birth month. For 02/07/2008 that is 12 - 7 = 5. NumMonths ← 12 - MONTH(MyDOB) MONTH(MyDOB) used to get the month [1] Subtracted from 12 and assigned to NumMonths [1] (c) Array definition: a 1D array with 7 elements [1] The array is of type STRING [1] Step 1: store the day names in the array, "Sunday" in the first element, "Monday" in the second and so on [1] Step 2: use the function DAYINDEX() on MyDOB to get the day number [1] Step 3: use that number as the index to find the matching name in the array [1] Step 4: output that name [1] KEY IDEA Use the date functions from the insert, and use a day number as an array index to find the day name. TOTAL 9 marks Official mark scheme VIDEO ▶ Starts at Q2 (7:33) Starts at Q2 (7:33) · by Pseudocode Pro. Tap the picture to open it on YouTube.