Most of these have to be traced. A loop whose body contains two additions rather than one runs four times and prints fourteen; the wrong options are the sum of the counters with the constant forgotten, that sum with the loop read as running to five, and the value you get by adding the constant once after the loop instead of once on every pass. A recursive function four calls deep returns six, with the value produced by a base case that stops one step early sitting beside it.
Two questions are about where a name points. A procedure declares a local variable that happens to share a name with one outside it, assigns to it, prints it, and returns — twenty, then five, because there were two variables all along. The explanation makes the point that the declaration is what settles this: without it, whether an assignment inside a procedure creates a local or writes to the outer variable depends on the language, and a question that leaves that out has no single right answer. The other is the same idea at the boundary of a call: one procedure, one line, doubling its parameter, run once by value and once by reference, printing seven in one case and fourteen in the other.
Object orientation is done by matching rather than reciting. A class keeps its balance where nothing outside can reach it and offers methods that check before they change — encapsulation. A subclass supplies its own version of a method its parent already has, so the same call behaves differently depending on the object it lands on — polymorphism, and confusing that with the inheritance that makes it possible is the usual slip. Then a Printer and a Scanner that both need to log something, where a subclass relationship would assert that a printer is a kind of scanner, and composition is the alternative.
The last three are judgement rather than trace. A paradigm is chosen against a stated requirement — a pipeline of transformations that must be reproducible — with the right answer available for the wrong reason ("it is the most modern") as a distractor. A function valid from one to a hundred is tested at zero, one, a hundred and a hundred and one, not in the comfortable middle. A program that runs to the end and prints the wrong number has a logic error, which tells you where to look. And a refactor that pulls four repeated lines into one procedure buys maintainability, not speed, because nothing in the case said anything about speed.
Every program described is invented, and every trace has been checked by hand. Nothing is reproduced from any exam board specification, past paper or mark scheme.
Zestly is an independent study tool. It is not affiliated with any exam board and it is not an exam centre.
Ten invented programs and design cases: a four-pass loop with two additions in its body, calc(3) returning six, a local declaration shadowing an outer count, one procedure doubling its parameter by value and by reference, a BankAccount and a SavingsAccount, a Printer that is not a kind of Scanner, a reproducible pipeline of transformations, a function valid from one to a hundred, a wrong total from an initialiser, and four lines repeated three times. Twelve flashcards carry the vocabulary — iteration, recursion, base case, stack frame, pass by value and by reference, local and global scope, encapsulation, inheritance, polymorphism, boundary testing.
Consider this pseudocode: total = 0. FOR i FROM 1 TO 4: total = total + i. total = total + 1. END FOR. PRINT total. What is the final value printed?
14
Take one pass at a time and write the value down after each of the two lines. With i as one, total goes to one and then to two. With i as two, to four and then five. With i as three, to eight and then nine. With i as four, to thirteen and then fourteen. So fourteen is printed, and the quick way to see it is that each pass adds the counter plus one: two, three, four, five, which is fourteen. Ten is the sum of the counters alone, one to four, with the constant forgotten entirely — the usual result of reading the loop body as a single line. Fifteen is the same sum with the loop read as running to five, so it combines that omission with the inclusive-range slip. And eleven is what you get if the constant is added once after the loop rather than once on every pass.
Try this quiz →Try this exam →Practice these flashcards →Try this written work →