9618/22/M/J/24 question 1: worked solution (May/June 2024, paper 22)
Show as plain textHide 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. Q21 9618/22/M/J/24 original Q1 Structured · 10 marks Worked solution (a) Decide what each statement does: FOR and UNTIL repeat, IF selects, READFILE and WRITEFILE are input/output: Pseudocode example Selection Iteration Input/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: Expression Function(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 IDEA FOR and UNTIL are iteration, IF is selection, file statements are input/output; document variables in an identifier table. TOTAL 10 marks Official mark scheme VIDEO ▶ Starts at Q1 (0:24) Starts at Q1 (0:24) · by Pseudocode Pro. Tap the picture to open it on YouTube.