These seven questions cover problem solving and algorithms in the order of the lessons. Attempt each on paper before opening the answer.
For exam pace, use the timed original practice session builder.
Questions
Question 1. A program should read the marks of four students and display the highest. List the tasks in terms of input, process and output.
Answer
In: four marks. Process: compare the marks and keep the largest seen so far. Out: the highest mark. A fuller split would also list “start with the first mark as the current highest” as its own task.
Question 2. Trace this and give the final values of a and b.
SET a = 2
SET b = 10
WHILE a < b
SET b = b - 1
SET a = a + 2
END WHILE
OUTPUT a, b
Answer
Start: a = 2, b = 10. Pass 1: b = 9, a = 4 (4 < 9 true). Pass 2: b = 8, a = 6 (6 < 8 true).
Pass 3: b = 7, a = 8 (8 < 7 false). The output is 8 and 7.
Question 3. A flowchart reads n and asks n MOD 2 = 0?. The Yes exit outputs “Even” and the No exit outputs “Odd”.
What is the output for n = 17, and for n = 0?
Answer
For 17, 17 MOD 2 = 1, so the answer is No and the output is Odd. For 0, 0 MOD 2 = 0, so the output is Even. Zero is an even number, which makes it a useful test input.
Question 4. Name the flowchart symbol for each step.
- (a) Start
- (b) INPUT price
- (c) SET total = total + price
- (d) total > 100?
Answer
(a) Oval. (b) Parallelogram. (c) Rectangle. (d) Diamond, with two labelled exits, Yes and No.
Question 5. A cinema booking allows 1 to 6 tickets per order. Choose six test inputs and label them normal, boundary or invalid.
Answer
Normal: 3. Boundary: 1 and 6 accepted, with 0 and 7 just outside and rejected. Invalid: “two” or 2.5, rejected. That gives seven inputs, which covers every category.
Question 6. What does this output?
SET sum = 0
FOR i = 1 TO 7
IF i MOD 2 = 1 THEN
SET sum = sum + i
END IF
NEXT i
OUTPUT sum
Answer
The condition is true for the odd values of i: 1, 3, 5 and 7. The sum grows as 1, 4, 9 and 16. The output is 16.
Question 7. A shop gives a 10% discount when the bill is RM100 or more. The code says IF total > 100 THEN. Which input exposes the fault, and what should the output be?
Answer
The input RM100 exposes it. The rule says RM100 qualifies, so the amount to pay should be 100 − 10 = RM90. The code tests 100 > 100, which is false, so it charges RM100. Change > to >=.
If you got these wrong
- Question 1: read breaking a problem into smaller tasks.
- Questions 2 and 6: read tracing pseudocode step by step.
- Questions 3 and 4: read designing a flowchart.
- Questions 5 and 7: read testing normal, boundary and invalid inputs.
Log the slips with the mistake log and paper-error review. For teacher support, see online one-to-one Computer Science tuition.