April 2000 QUESTION 4 Total Marks: 15 Marks |
Click here to access other
questions
SUGGESTED SOLUTIONS |
Do not award half marks. Do not deduct marks for trivial syntactic errors. Alternative correct answers should be given credit, unless otherwise indicated in the marking scheme. (a)(i)Explain the difference between
pass by value and pass by reference [2marks] (b)Write a procedure,called reference
which takes in two reference parameters x and y The procedure should
change the two values such that on exit,x is equal to the sum of the
two values,and y is equal to the difference between the two values.[3
marks ] (c)Using a switch statement,write a function,called
itoa which takes a single integer parameter.If the parameter supplied
is 1 then the function should return the character a if 2 then the
character b should be returned; in all other cases the function should
return the character c [4marks ] (d)In mathematics, N (known as N Factorial
can be computed using the formula N =N *(N -1 ). The base case,0!
is defined as being 1. For example,3! =3 *2 *1 *1 =6. Write a recursive
function,called factorial which takes as its parameter an integer
n and will return N .[5 marks ] |