Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 1 of 3.
Use the SETDATE function from the insert:
MyDOB ← SETDATE(17, 11, 2007)
Correct statement [1]
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]
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]
▶ Starts at Q2 (7:33)
Starts at Q2 (7:33) · by Pseudocode Pro. Tap the picture to open it on YouTube.
Solutions follow the official Cambridge mark schemes; marks are shown in grey. Videos are from other YouTube channels. Paper codes read component / series / year: M/J = May/June, O/N = October/November. Past-paper questions © UCLES, reproduced for classroom practice.