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.[3]
- (b)(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.[3]
- (b)(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.[2]
- (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.[7]
- (d)(i)The iterative function needs to be called three times with the same parameters as in part (b). 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.[1]
- (d)(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.[1]
Mark scheme
Marking points from the official mark scheme (Oct/Nov 2021). The mark or mark type is shown in brackets.
- [1] function with correct name and parameters
- [1] correct Div operator (or equivalent) used
- [1] code matches pseudocode
- [1] Suitable output identifying parameters for each call
- [1] All three correct function calls
- [1] ...outputting the return value for each call
- [1] 1 mark for 1 function with correct output
- [1] 1 mark for remaining 2 function calls with correct output
- [1] Iterative function, taking 2 parameters
- [1] Starting with return value (Total) as 1
- [1] Looping while X <> Y // might be 1 loop or two separate // returning when X = Y // looping until X==Y
- [1] Within each loop, outputting (X+Y) correctly when X<Y and Y<X
- [1] Each time X < Y, Total * 2 and X++
- [1] Each time Y < X Total DIV 2 and X--
- [1] Returning the Total after correct calculations
- [1] Calling function 3 times with correct Data and outputting
- [1] 1 mark for screenshot showing correct output for both functions
Write your answer and get it marked
On Oracle Prep you can write or photograph your own answer and have it marked by AI against this mark scheme, with feedback on what you missed.
Sign up free →