December 1999
OP216 : OBJECT ORIENTED PROGRAMMING

QUESTION 5

Total Marks: 15 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 5

Consider the following abstract data type declaration for an IntegerList type:

class IntegerList {
private:
int*s;
int n;
public:
IntegerList(int m,int*t); //Copy n characters from t to s
int Length(){return n;} //Return the length of the list
void UpdateAt(int i,int c) {
if(i>=0 &&i<=length())s [i ]=c;
  } //Update the element at index i with element c
  int ElementAt(int i){
    if(i>=0 &&i<=length())return s [i ];else return 0;
  } //Return the element at index i };
};      

 

(a)

Explain the difference between deep and shallow (or member-wise) copying of objects.

 

[3]
(b)

Write a constructor function for the IntegerList class which performs a deep copy of the object.You may not use any library functions.

 

[6]
(c) Write a function Reverse ,the signature of which is given below,which takes an IntegerList object and returns a new IntegerList which is the reverse of the original IntegerList .You may not use any library functions.
IntegerList Reverse(IntegerList s);
[6]