December
1999 QUESTION 2 Total Marks: 15 Marks |
Click here to access other
questions
SUGGESTED SOLUTIONS |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(a) |
Template classes are an example of polymorphism .Explain what is meant by polymorphism . Polymorphism
|
[2] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(b) |
Declare a pointer to an object of type Queue ,with an integer template type. Queue
|
[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(c) |
Show how this object can be allocated using the new operator. MyQueue=new Queue();[1 mark ]
|
[1] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(d) |
Write a polymorphic iterative function,called RemoveItemN ,the signature of which is given below,which takes a reference to a queue Q and an integer x ,and will remove and return the x ’th item from the queue Q .The rest of the queue should remain unchanged.You should assume that counting queue elements starts at zero,and you may use the functions which have been declared in the class Queue . template <class T> A sample definition of RemoveItemN follows:
|
[6] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
(e) |
Write a polymorphic recursive function,called Reverse ,the signature of which is given below,which takes a reference to a queue Q and reverses the queue.To reverse a queue,items should be recursively removed from the queue,and then added to the queue as the recursive stack is unwound.You may use the functions which have been declared in the class Queue . template <class T> A sample definition
of Reverse follows:
And the following
marking scheme should be used: |
[5] |