These seven questions cover programming foundations. Attempt each on paper, then open the answer to compare.
For exam pace, set up a session with the timed original practice session builder.
Questions
Question 1. Choose a data type for each: (a) the number of books borrowed, (b) an average mark such as 72.5, (c) the class name “4 Amanah”, (d) whether a library card is valid.
Answer
(a) Integer. (b) Real. (c) String. (d) Boolean.
The average needs a decimal part, and the class name contains letters.
Question 2. Which of these should be a constant: the days in a week, the tickets bought in an order, a school pass mark of 40, a player’s current score?
Answer
The days in a week (7) and the school pass mark (40) should be constants because they are fixed. The tickets bought and the current score change, so they are variables.
Question 3. How many times does this loop body run, and what is the last value printed?
FOR i = 3 TO 11
OUTPUT i
NEXT i
Answer
The passes are 11 − 3 + 1 = 9. The values printed are 3 to 11, so the last is 11.
Question 4. Trace and give the final x and count.
SET x = 1
SET count = 0
WHILE x < 50
SET x = x * 2
SET count = count + 1
END WHILE
Answer
x becomes 2, 4, 8, 16, 32 and 64, with count rising from 1 to 6. After x = 32 the check 32 < 50 is true, so one more pass makes x = 64. Then 64 < 50 is false. The final values are x = 64 and count = 6.
Question 5. What does this output for marks 75, 60 and 59?
IF mark >= 80 THEN
OUTPUT "A"
ELSE IF mark >= 60 THEN
OUTPUT "B"
ELSE
OUTPUT "C"
END IF
Answer
For 75, the first test fails and 75 >= 60 passes, giving B. For 60, the second test passes on the boundary, giving B. For 59 both tests fail, giving C.
Question 6. Trace this and state the output.
FUNCTION triple(n)
RETURN n * 3
END FUNCTION
SET a = 2
SET b = triple(a) + triple(a + 1)
OUTPUT a, b
Answer
triple(2) returns 6. triple(3) returns 9. So b = 6 + 9 = 15.
The variable a is unchanged. The output is 2 and 15.
Question 7. The values 5 and 8 are added in a program. What is the result if both are integers, and what if both are strings that are joined?
Answer
As integers, 5 + 8 = 13. As strings, joining gives “58”. The same digits give different results, which is why the data type must be decided before the operation.
If you got these wrong
- Questions 1, 2 and 7: read variables, constants and data types.
- Questions 3, 4 and 5: read writing loops with correct boundaries.
- Question 6: read tracing functions and parameters.
Log your slips with the mistake log and paper-error review. For teacher support, see online one-to-one Computer Science tuition.