Worked solution from the Programming Paper 2 Problem-solving and Programming booklet, Part 1 of 3.
Work out what kind of value each assignment stores:
| Assignment statement | Data type |
|---|---|
| MyVar1 ← Total1 / Total2 | REAL |
| MyVar2 ← 27/10/2023 | DATE |
| MyVar3 ← "Sum1 / Sum2" | STRING |
| MyVar4 ← Result1 AND Result2 | BOOLEAN |
MyVar1 is REAL (a division can give a decimal) [1]
MyVar2 is DATE [1]
MyVar3 is STRING (it is in quotes) [1]
MyVar4 is BOOLEAN (AND gives TRUE or FALSE) [1]
Evaluate each expression with Active = TRUE, Fraction = 0.2, Code = "Ab12345":
| Expression | Evaluates to |
|---|---|
| Fraction >= 0.2 AND NOT Active | FALSE |
| INT((Fraction * 100) + 13.3) | 33 |
| STR_TO_NUM(MID(Code, 4, 2)) + 5 | 28 |
| LENGTH("TRUE" & Code) | 11 |
Fraction >= 0.2 is TRUE, NOT Active is FALSE, so TRUE AND FALSE = FALSE [1]
0.2 × 100 = 20, 20 + 13.3 = 33.3, INT gives 33 [1]
MID(Code, 4, 2) = "23", converted to 23, 23 + 5 = 28 [1]
"TRUE" & Code = "TRUEAb12345", which has 4 + 7 = 11 characters [1]
Write: use a program library (a library of ready-made routines). [1]
Write both parts:
Type: adaptive maintenance [1]
Reason: the user requirements change (or the law changes, so the program must change) [1]
▶ Starts at Q1 (1:52)
Starts at Q1 (1:52) · by Zafar Ali Khan (ZAK). 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.