A bakery uses an automated system to calculate scaled ingredient weights for different sizes of custom cakes.
Here is the pseudo-code for an algorithm that validates a base recipe weight and calculates the scaled flour requirements.
1 # Setup parameters for scaling recipe
2 SET cakeSizes TO ["S", "M", "L", "XL", "XXL"]
3 SET scaleList TO [0.5, 1.0, 1.5, 2.0, 2.5]
4 SET validData TO False
5
6 # Perform validation loop
7 WHILE (validData = False) DO
8 SEND "Enter base flour weight in grams:" TO DISPLAY
9 RECEIVE baseWeight FROM (INTEGER) KEYBOARD
10
11 IF (baseWeight >= 150) THEN
12 SET validData TO True
13 SEND "Base weight set to " & baseWeight TO DISPLAY
14 ELSE
15 SEND "Error: Weight must be 150g or more" TO DISPLAY
16 END IF
17 END WHILE
18
19 # Calculate scaled ingredients
20 FOR i FROM 0 TO (LENGTH(cakeSizes) - 1)
21 SET weightRequired TO baseWeight * scaleList[i]
22 SET roundedWeight TO ROUND(weightRequired)
23 SEND "Size " & cakeSizes[i] & " requires " & roundedWeight & "g" TO DISPLAY
24 END FOR
Programmers use basic programming constructs when they write code.
Complete the table to identify line number(s) from the pseudocode that illustrate an example of different programming constructs.
| Programming construct | Line number(s) |
|---|---|
| A condition controlled loop | |
| A comment | |
| A selection construct | |
| A subprogram call |
50 exam-style questions on Edexcel GCSE Computer Science Constructs, covering Structural components of programs and Writing programs with control constructs. Each one has a worked solution and a mark scheme showing where the marks go.