August 2000
OP216 : OBJECT ORIENTED PROGRAMMING

QUESTION 2

Total Marks: 15 Marks

Click here to access other questions

Click to access
SUGGESTED SOLUTIONS
for Question 2

Consider the following definition of a polymorphic queue, and the class PrintJobs:
template <class T>
class Queue {
  private:
  int size;
  T *first, *last;
  public:
  void Add(T); // Add item to the back of the queue
  T Remove(); // Remove and return the item at the front of the queue
  int Size(); // Return the number of elementes in the queue
}
class PrintJobs {
  char* JobName;
  void* Job;
  PrintJobs* next;
}
(a) Explain what is meant by a template class in C++, and give an example of where it may be useful to employ a template class. [2 marks]

(b) Construct an object MyQueue, which is an instantiation of the Queue class with template type PrintJobs. [2 marks]

(c) Implement the function Add, such that it takes an object of template type T and adds it to the back of the queue. [4 marks]

(d) Implement the function SplitQueue, such that it takes in a reference to a queue and separates it into two queues a and b, such that any PrintJob with the name "priority" is put into queue a, and the others into queue b. [5 marks]

(e) Give the name for the form of parameter passing used in the above SplitQueue function, and explain what effect this type of parameter passing has. [2 marks]