Worked solution from the Data Types and Structures Paper 2 Problem-solving and Programming booklet, Part 1 of 4.
Choose a meaningful name for each item and the data type that matches its example value.
| Example value | Explanation | Variable name | Data type |
|---|---|---|---|
| "Mr Khan" | The name of the customer | CustomerName | STRING |
| 3 | The number of items in the order | NumItems | INTEGER |
| TRUE | To indicate whether this is a new customer | NewCustomer | BOOLEAN |
| 15.75 | The deposit paid by the customer | Deposit | REAL |
Row 1 has a suitable name and STRING [1]
Row 2 has a suitable name and INTEGER [1]
Row 3 has a suitable name and BOOLEAN [1]
Row 4 has a suitable name and REAL [1]
Work out each expression using the example values.
| Expression | Evaluates to |
|---|---|
| (Total * DepRate) + 1.5 | 249.50 |
| RIGHT(Description, 7) | "(small)" |
| (LENGTH(Description) - 8) > 16 | TRUE |
| NUM_TO_STR(INT(DepRate * 10)) & '%' | "20%" |
(124.00 × 2.00) + 1.5 = 249.50 [1]
The last 7 characters are "(small)" [1]
The description has 30 characters, 30 - 8 = 22, and 22 > 16 is TRUE [1]
2.00 × 10 = 20, as a string with % it is "20%" [1]
Use a record to hold the different data types, then an array of those records.
Declare a record (composite) type containing all the data items needed for one order, even though they are of different data types [1]
Declare an array of that record type [1]
Each element of the array holds the data for one customer order [1]
▶ Starts at Q1 (0:25)
Starts at Q1 (0:25) · 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.