December
1999 QUESTION 1 (Compulsory) Total Marks: 30 Marks |
Click here to access
other questions
Click to access |
(a) |
(i)Explain the difference between a class and an object .[2 marks ] (ii)State what a friend function is in C++.[2 marks ] (iii)Give one example of when a friend function may be used.[1 mark ] (iv)Explain the difference between multiple
and single inheritance. (v)Describe what is meant by a pure virtual function in C++.[2 marks ] (vi)Declare a pure virtual function,called foobar ,which takes no parameters and has an int return type.[1 mark ]
|
[10] |
(b) |
(i)Explain the difference between pass by value and pass by reference parameter passing,and describe how pass by reference is implemented in C++.[3 marks ] (ii)Write a function,called avswap ,the signature of which is given below,which takes in two reference parameters x and y ,and returns the average of the two parameters.On exit,the values of x and y should be exchanged.int avswap(int* x, int* y); [5 marks ]
|
[8] |
(c) |
(i)Define the purpose of a class constructor .[1 mark ] (ii)Write a class,called StudentMarks ,which is to be used to store sets of student marks.Your class should contain the following member declarations: •A default constructor; (iii)Add to your class the declaration of an overloaded constructor,which takes two parameters x which is an array of integers and y ,which is the length of the array.[1 mark ] (iv)Add to your class an inline accessor function,called MarkAt ,which takes in a single parameter x ,and returns the value stored in the array at that index. [2 marks ] (v)Add to your class a function,called
ReadPass ,the signature of which is given below,which will return
the index of the first element of the array to have a mark greater
than 30,or -1 if there is none. |
[12] |