Computer Science · Oct / Nov 2021 · Paper 22 · Question 4
0478
As printed in the paper
The question as text
The pseudocode algorithm should work as a calculator and output the result. 1 Continue 1 2 WHILE Continue = 0 3 OUTPUT "Enter 1 for +, 2 for -, 3 for * or 4 for /" 4 INPUT Operator 5 OUTPUT "Enter the first value" 6 INPUT Value1 7 OUTPUT "Enter the second value" 8 OUTPUT Value2 9 IF Operator 10 1: Answer Value1 + Value2 11 2: Answer Value1 - Value2 12 3: Answer Value1 * Value2 13 4: Answer Value1 / Value2 14 ENDCASE 15 OUTPUT "The answer is ", Value1 16 OUTPUT "Do you wish to enter more values (Yes or No)?" 17 INPUT MoreValues 18 IF MoreValues = "No" 19 THEN 20 Continue 1 21 ENDIF 22 UNTIL Continue = 0
Read automatically from the paper; the printed page above is exact.
Show the answer and mark scheme
4(a)[5]
One mark for error identified and suggested correction (Max three)
Line 8 OUTPUT Value2 – should be INPUT Value2
Line 9 IF Operator – should be CASE OF Operator
Line 15 OUTPUT "The answer is ", Value1 – should be Answer
The loop may be corrected using a number of alternative methods:
One mark for error identified and suggested correction (Max two)
Method 1
Line 1 Continue ← 1 should be Continue ← 0
Line 22 UNTIL Continue = 0 should be ENDWHILE // Line 2 WHILE Continue = 0 should be REPEAT and Line 22 UNTIL Continue = 0 should be Until Continue = 1
OR
Method 2
Line 2 WHILE Continue = 0 should be REPEAT
Line 20 Continue ← 1 should be Continue ← 0 // Line 1 Continue ← 1 should be Continue ← 0 and Line 22 UNTIL Continue = 0 should be Until Continue = 1
OR
Method 3
Line 2 WHILE Continue = 0 should be WHILE Continue = 1
Line 20 Continue ← 1 should be Continue ← 0 and Line 22 UNTIL Continue = 0 should be ENDWHILE
Corrected algorithm example 1
1 Continue ← 0
2 WHILE Continue = 0 (DO)
3 OUTPUT "Enter 1 for +, 2 for -, 3 for * or 4 for /"
4 INPUT Operator
5 OUTPUT "Enter the first value"
6 INPUT Value1
7 OUTPUT "Enter the second value"
8 INPUT Value2
9 CASE OF Operator
10 1: Answer ← Value1 + Value2
11 2: Answer ← Value1 - Value2
12 3: Answer ← Value1 * Value2
13 4: Answer ← Value1 / Value2
14 ENDCASE
15 OUTPUT "The answer is ", Answer
16 OUTPUT "Do you wish to enter more values (Yes or No)?"
17 INPUT MoreValues
18 IF MoreValues = "No"
19 THEN
20 Continue ← 1
21 ENDIF
22 ENDWHILE
Corrected algorithm example 2
1 Continue ← 1
2 REPEAT
3 OUTPUT "Enter 1 for +, 2 for -, 3 for * or 4 for /"
4 INPUT Operator
5 OUTPUT "Enter the first value"
6 INPUT Value1
7 OUTPUT "Enter the second value"
8 INPUT Value2
9 CASE OF Operator
10 1: Answer ← Value1 + Value2
11 2: Answer ← Value1 - Value2
12 3: Answer ← Value1 * Value2
13 4: Answer ← Value1 / Value2
14 ENDCASE
15 OUTPUT "The answer is ", Answer
16 OUTPUT "Do you wish to enter more values (Yes or No)?"
17 INPUT MoreValues
18 IF MoreValues = "No"
19 THEN
20 Continue ← 0
21 ENDIF
22 UNTIL Continue = 0
4(b)[5]
One mark per bullet
MP1
Appropriate loop (begin and end) / otherwise selection
MP2
Testing both ends of condition
MP3
Suitable message
MP4
Input/re-input
WHILE Operator < 1 OR Operator > 4 (DO)
OUTPUT "Enter 1, 2, 3 or 4"
INPUT Operator
ENDWHILE
Alternative answer
REPEAT
IF Operator < 1 OR Operator > 4
THEN
OUTPUT "Enter 1, 2, 3 or 4"
INPUT Operator
ENDIF
UNTIL Operator >= 1 AND Operator <= 4
One mark
After line 4 / between lines 2 and 5
Make a free account to save your answers and see your weak topics and ask the AI why a wrong answer is wrong.

