Computer Science
Programming and reasoning
- 1.
A function receives integer x by value, assigns x=x+1 and returns nothing. The caller's variable n was 5. State n after the call and explain why.
[3 marks] · no calculatorAnswer explanation
Draft walkthroughs are based on marking guidance, not independently verified derivations.
- Assignment changes the local parameter's storage. With no returned value assigned back and no shared reference to n, the local change cannot update the caller's integer variable.
Marking points
- The local x becomes 6.
- The caller's n remains 5.
- Pass-by-value copies the integer value rather than binding x to the caller's variable.
Examiner tip: The stated integer pass-by-value model avoids object-mutation ambiguity.
- 2.
Distinguish validation from verification for an entered date of birth, giving one example of each.
[3 marks] · no calculatorAnswer explanation
Draft walkthroughs are based on marking guidance, not independently verified derivations.
- Rule checks reject impossible values, not every false value. Comparing to a trustworthy source addresses transcription accuracy, which a calendar-range test alone cannot establish.
Marking points
- Validation checks conformity to rules such as a real calendar date and permitted range.
- Verification checks that input matches its source, such as comparison with an original document.
- A valid date can still be the wrong person's date or be copied incorrectly.
Examiner tip: Passing validation does not prove factual correctness.
- 3.
Trace: total=0; FOR i=1 TO 4 inclusive: IF i mod 2=0 THEN total=total+i ELSE total=total-1. Give total after each iteration.
[3 marks] · no calculatorAnswer explanation
Draft walkthroughs are based on marking guidance, not independently verified derivations.
- Odd iterations subtract one; even iterations add the current index. Carry the updated total into the next iteration rather than recomputing from the original zero.
Marking points
- After i=1 and i=2: -1, 1.
- After i=3: 0.
- After i=4: 4.
Examiner tip: Apply the ELSE only on odd iterations, not after every addition.
- 4.
A recursive function F(n) returns 1 if n=0, otherwise returns n*F(n-1), for integer n>=0. Trace F(4), and explain the base case's role.
[3 marks] · no calculatorAnswer explanation
Draft walkthroughs are based on marking guidance, not independently verified derivations.
- Each pending call waits for the smaller argument's result. F(0)=1 lets multiplication build 1, 2, 6 and 24 on return; without a reachable stopping case the descent would continue.
Marking points
- Calls reach F(4), F(3), F(2), F(1), F(0).
- Unwinding gives F(4)=24.
- The base case ends recursion and supplies the multiplicative identity.
Examiner tip: Termination relies on the nonnegative-integer precondition and decreasing n.
- 5.
A function accepts integer ages from 16 through 120 inclusive. Design a minimal boundary-focused test set that checks both acceptance boundaries and adjacent rejection, plus one distinct type-error case; state expected outcomes.
[4 marks] · no calculatorAnswer explanation
Draft walkthroughs are based on marking guidance, not independently verified derivations.
- Test just inside and just outside each permitted edge. A text case exercises parsing/type behaviour that numeric boundary tests cannot cover; expected outcomes make the tests checkable.
Marking points
- 15 rejected, 16 accepted.
- 120 accepted, 121 rejected.
- A nonnumeric string such as 'sixteen' is rejected without crashing.
- These target off-by-one and type handling separately; normal-value tests can supplement them.
Examiner tip: Do not list only normal ages and call the set boundary testing.
- 6.
Two tasks both execute read counter; add 1 locally; write counter. Starting at zero, show an interleaving ending at 1 rather than 2, and propose a synchronisation remedy with its scope.
[4 marks] · no calculatorAnswer explanation
Draft walkthroughs are based on marking guidance, not independently verified derivations.
- The operation's apparent simplicity hides three steps. Correct synchronisation must make the entire state transition indivisible to competitors, so the second increment sees the first increment's result.
Marking points
- Both tasks can read zero before either writes.
- Both compute one and write one, losing an increment.
- Protect the full read-modify-write sequence with a shared lock, or use an atomic increment.
- Locking only the final write does not prevent both tasks using the same stale read.
Examiner tip: A separate lock per task provides no mutual exclusion over shared state.
Marking points are indicative, not an official mark scheme. Accept equivalent valid methods and supported interpretations that address the task; award each mark once without requiring the model wording.