Practical Seven

Object Orientation : Inheritance and Polymorphism

due : 12am (midnight) 28 April 1997


Part One

Design and implement an object-oriented framework to add data items of different types to a stack, implemented as a linked list.

The basic data type added to the stack must be an Abstract Data Type, with no physical meaning beyond that it defines the properties of all nodes in a list i.e. it contains pointers to other elements. From this ADT, derive a set of element types (eg. StringType, IntegerType, etc.), each with the relevant data types encapsulated and the Output method over-ridden to output the associated data.

Your ADT should be declared similar to the following example:

class ADT
{
public:
   ADT *Next;
   virtual void Output () {};
};

Your Stack class must be able to insert elements of type ADT into the stack. This will support all derived classes as well, thus generalising the data structure across element types.

Part Two

Create an abstract class for the Stack so that elements can be added/removed without the knowledge of the type of the data structure. In this abstract class, use methods called Add and Remove. Then derive a Stack from the base class.

To indicate the flexibility of the abstraction, derive a Queue as well, so that your main program can create either a stack or queue and manipulate the data structure with the same set of methods (Add/Remove).