December
1999 QUESTION 1 (Compulsory) Total Marks: 30 Marks |
Click here to access other
questions
SUGGESTED SOLUTIONS |
(a) |
(i)Name two type modifiers other than unsigned .[2 marks ] Any two of the following,one mark for each:signed ,long or short . (ii)Name two storage class modifiers other than volatile .[2 marks ] Any two of the following,one mark for each:extern ,auto ,register ,static or const .
|
[4] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(b) |
(i)Declare a two dimensional array of integers,called fb ,which is of size 3 ×3,and initialise it with the values 1 through to 9.[2 marks ] int fb [3 ][3
]=1,2,3,4,5,6,7,8,9; (ii)Declare a dynamic array of floating point integers,called floaters ,which may have values implicitly changed and therefore should not be optimized.The size of the array should only be decided at allocation time.[2 marks ] volatile float**floaters;
|
[4] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(c) |
What is the result of applying the bitwise operators in the following expressions? (i)7 & 7 [1 mark ] 7
7
0
2
|
[4] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(d) |
Give the result of applying the arithmetic operators in the following expressions, when x =3,y =5 and z =7: (i)(x+y*z) [1 mark ] 38
1
20
8
|
[4] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(e) |
Given the following definition of the
procedure foobar :
Trace the following calls and produce their output: (i)foobar(1,-1);[1 mark ] Suspend task;
Running task;
Delete task;
Halt task;Delete task;
|
[4] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(f) |
Write a procedure,called Exchange ,the signature of which is given below,which takes in three integer parameters,x ,y and z by reference.On exit,the value of z should be equal to the sum of the other two parameters,and the other two parameters should be exchanged. void Exchange(int*x,int*y,int*z); A sample definition of Exchange follows
Summing *x and *y to give *z ;(1 mark) Declaring a local temporary variable,and assigning one of the values to it; (1 mark) Swapping the two values using the temporary variable.(1 mark)
|
[4] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(g) |
A Fibonacci sequence is a sequence of numbers where the next number in the sequence is calculated by the sum of the previous two numbers.For example,a sequence which started with the numbers (1,2)would have as its third entry 3 (calculated by 1+2).The next number would be 5 (calculated by 2+3)and so on. Write an iterative procedure,called Fibonacci ,the signature of which is given below, which takes three parameters,x ,y and z .The procedure should use x and y as the initial two entries in the sequence,and print out the next z entries. void Fibonacci(int x,int y,int z); A sample definition of Fibonacci follows:
And the following marking scheme should be used:
Declaring
a suitable iterative structure,bounded by z iterations; Calculating
the value of third on each iteration;(1 mark) Correctly updating the value of first with the current value of second on each iteration;(1 mark) Correctly
updating the value of second with the value of third . |
[6] |