August 2000
OP216 : OBJECT ORIENTED PROGRAMMING

QUESTION 1 (Compulsory)

Total Marks: 30 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 1

(a) Briefly explain what is meant by each of the following terms in object oriented
programming.
(i) Constructor; [1 mark]
(ii) A public member of a class; [1 mark]
(iii) Function overloading; [1 mark]
(iv) Static member; [1 mark]
(v) A friend function; [1 mark]

(b) (i) State the number of destructors a class may have. [1 mark]
(ii) Briefly describe what is meant by an abstract class. [2 marks]
(iii) Briefly explain how polymorphism can promote extensibility. [2 marks]

(c) (i) Write a class, called Motherboard, which contains the following:
• The private data members CPU, which is of type String, and the memory, which
is an integer (in megabytes).
• A constructor function which takes two parameters, which initialise the private
data members. [4 marks]
(ii) Write an accessor method, which should be declared as a member of the Motherboard class, which will return the amount of memory available. [2 marks]
(iii) Write a deep copy constructor for your Motherboard class. which takes a constant reference to an object of type Motherboard as an argument, and will create a new Motherboard object by performing a deep copy. [4 marks]

(d) Give the output of the following C++ program:
void main(void) {
  int xs[]={1,2,3},*p1,*p2,*p3, *p4;
  p1 =xs;
  p2 =p1;
  p3 =p1++;
  *p2=30;
  p4 =&xs[2];
  printf("p1 is %d\n",*p1);
  printf("p2 is %d\n",*p2);
  printf("p3 is %d\n",*p3);
  printf("p4 is %d\n",*p4);
}
[4 marks]

(e) Write a template function, called IsMember, which takes three arguments. The first argument is an array of template type T, the second is a datum of template type T, and the third is an integer specifying the length of the array. The function should return the index of the first element in the array matching the datum, or 0 if there is no matching entry. You may assume that overloadings of any necessary operators exist. [6 marks]