Cambridge AS Level Computer Science 9618 · 11.1 Programming Basics

Q11 · 9618/22/M/J/23 Q2

Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 1 of 3.

Q119618/22/M/J/23original Q2Structured · 9 marks
Question 2 from 9618/22/M/J/23

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 IDEAUse 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

Mark scheme for 9618/22/M/J/23 question 2
VIDEO
▶ 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.