August
1997 QUESTION 1 (Compulsory) Total Marks: 20 Marks |
Click here to access other
questions
SUGGESTED SOLUTIONS |
| 1. | (a) What is the difference between public and private data members? | [4] | |
| Public members are accessed by the clients/friends of the class. They can be accessed at any time from outside the object. | [2] | ||
| Private data members can only be accessed by member functions of the data. They are not intended to be invoked from outside an object. | [2] | ||
| [4 marks] | |||
| (b) Use C++ to describe the header of a function called MEOW. MEOW is a member of the class cat but is defined outside it. MEOW takes no parameters and returns void. | [2] | ||
| void Cat : : MEOW( ); | |||
| deduct one mark for each syntax error or omission, minimum zero. | |||
| [2 marks] | |||
| (c) Use C++ to show the declaration of a class square that derives from rectangle, which in turn derives from shape | [3] | ||
| class Square : Public Rectangle { }; | |||
| deduct one mark for each syntax error or omission, minimum zero. | |||
| [3 marks] | |||
| (d) When is copy constructor called and when is a destructor called? | [4] | ||
| A constructor is called whenever a temporary copy of an object is created. This happens everytime an object is passed by value. | [2] | ||
| The destructor is called each time an object is destroyed, either because it goes out of scope or because a delete is applied to its pointer. | [2] | ||
| [4 marks] | |||
| (e) Differentiate between the following: | |||
| (i) class and object | [2] | ||
| A class is an implementation of an abstract data type while an object is an instance of a class. | [2] | ||
| (ii) method and message | [2] | ||
| A Message is a request to an object to invoke one of its methods. A Method is associated to a class and is invoked by a message. | [2] | ||
| [4 marks] | |||
| (f) List the three types of inheritance. | [3] | ||
| Public, Protected and Private Inheritance. | |||
| [3 marks] | |||