9618/41

Computer Science 9618/41October/November 2021

Cambridge A-Level · Practical · worked solutions for every part, with the mark scheme

3
questions
75
marks
150
minutes

Topics Programming Paradigms (Procedural and Object-oriented) · Recursion · Algorithms and Abstract Data Types · File Processing and Exception Handling

Q1RecursionProgramming Paradigms (Procedural and Object-oriented)Free sample

Study the following pseudocode for a recursive function.

FUNCTION Unknown(BYVAL X, BYVAL Y : INTEGER) RETURNS INTEGER
 IF X < Y THEN
  OUTPUT X + Y
  RETURN (Unknown(X + 1, Y) * 2)
 ELSE
  IF X = Y THEN
   RETURN 1
  ELSE
   OUTPUT X + Y
   RETURN (Unknown(X - 1, Y) DIV 2)
  ENDIF
 ENDIF
ENDFUNCTION

The operator DIV returns the integer value after division e.g. 13 DIV 2 would give 6

(a)

Write program code to declare the function Unknown().

Save your program as question 1.

Copy and paste the program code into part 1(a) in the evidence document.

3M
(b)

The main program needs to run all three of the following function calls and output the result of each call:

Unknown(10, 15)
Unknown(10, 10)
Unknown(15, 10)

(i)

For each of the three function calls, the main program needs to:

  • output the value of the two parameters
  • call the function with those parameters
  • output the return value.

Write the program code for the main program.

Save your program.

Copy and paste the program code into part 1(b)(i) in the evidence document.

3M
(ii)

Take a screenshot to show the output from part (b)(i).

Copy and paste the screenshot into part 1(b)(ii) in the evidence document.

2M
(c)

Rewrite the function Unknown() as an iterative function, IterativeUnknown().

Save your program.

Copy and paste the program code into part 1(c) in the evidence document.

7M
(d)

The iterative function needs to be called three times with the same parameters as in part (b).

(i)

For each of the three function calls, the main program needs to:

  • output the value of the two parameters
  • call the iterative function with those parameters
  • output the return value.

Amend the main program to perform these tasks.

Save your program.

Copy and paste the program code into part 1(d)(i) in the evidence document.

1M
(ii)

Take one or more screenshots to show the output of both functions for each set of parameters.

Copy and paste the screenshot(s) into part 1(d)(ii) in the evidence document.

1M

The rest of this paper

2 more questions
  • Q2Programming Paradigms (Procedural and Object-oriented) · File Processing and Exception Handling · Algorithms and Abstract Data Types30M
  • Q3Programming Paradigms (Procedural and Object-oriented) · Algorithms and Abstract Data Types · Recursion28M
Loading the full paper…