Cambridge AS Level Computer Science 9618 · 11.1 Programming Basics

Q21 · 9618/22/M/J/24 Q1

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

Q219618/22/M/J/24original Q1Structured · 10 marks
Question 1 from 9618/22/M/J/24

Worked solution

(a)

Decide what each statement does: FOR and UNTIL repeat, IF selects, READFILE and WRITEFILE are input/output:

Pseudocode exampleSelectionIterationInput/Output
FOR Index ← 1 TO 10 ... NEXT Index✓
WRITEFILE ThisFile, "**"✓
UNTIL Level > 25✓
IF Mark > 74 THEN READFILE ... ENDIF✓✓

FOR row: iteration only [1]

WRITEFILE row: input/output only [1]

UNTIL row: iteration only [1]

IF row: selection and input/output [1]

(b)

Choose a function that gives the data type on the left of each line:

ExpressionFunction(s)
MyInt ← ... (3.1415926)INT
MyChar ← ... ("Elwood", 3, 1)MID
MyString ← ... ( ... (27.509))NUM_TO_STR ( INT ( ... ) )
MyInt ← ... ( ... ("ABC123", 3))STR_TO_NUM ( RIGHT ( ... ) )

INT [1]

MID [1]

MyString ← NUM_TO_STR(INT(27.509)) [1]

MyInt ← STR_TO_NUM(RIGHT("ABC123", 3)) [1]

Other valid answers also score: CHR(INT(27.509)), TO_UPPER(NUM_TO_STR(27.509)), LENGTH(RIGHT("ABC123", 3)) or LENGTH(LEFT("ABC123", 3)).

(c)

Write both points:

Way of documenting: an identifier table [1]

One piece of information: what (each) variable is used for (its purpose), or an example value or initial value [1]

KEY IDEAFOR and UNTIL are iteration, IF is selection, file statements are input/output; document variables in an identifier table.
TOTAL 10 marks

Official mark scheme

Mark scheme for 9618/22/M/J/24 question 1
VIDEO
▶ Starts at Q1 (0:24)

Starts at Q1 (0:24) · 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.