Get a copy of the Lab 11 Template and use it as your starting code.
Run the template to make sure that it compiles, then complete the
List class by adding or replacing code
at each of the 9 numbered positions that appear in the program.
When you finish the List class, the test
code in main will produce correct output, namely: 2 1 3 4 as the list,
2 removed from the front, and 4
removed from the back
PART TWO - Making Subclasses
The class List allows users to add or remove data from either front
or back. All options are permitted.
Use inheritance to create two List subclasses: Stack and Queue.
Each of them is a restricted version of
the list.
In a stack, data is added
and removed from the front.
In a queue, data is added to
the back and removed from the front.
Stack and Queue should each offer the following operations which are
not available in List:
void add(int newData);
int removeData();
Notice how these function names don't say where data will be added or
where it will be removed from.
Such details are part of the definition of a stack or queue, so they
don't have to be spelled out in the
function names. These operations should be easy to implement
because Stack and Queue both inherit
some very useful member functions from List. They will only
require one or two lines of code! We
would also like to have the ability to print out all the data in a
Stack or Queue. Will you need to define
printAll member functions for Stack and Queue?
For a Stack or Queue, the functions addToFront, addToBack,
removeFromFront, and removeFromBack
are all illegal. These operations are inherited from List and
would normally be part of Stack and Queue.
To prevent their use outside the class, you can declare private dummy
versions of them. Notice that
after you do this, you will have two versions of these functions: one
inherited from List and one
redefined (a do-nothing dummy version) in the private part of your
subclass. Inside your Stack or
Queue class you can call either one. To call the inherited
version, you must put List:: in front of the
call; otherwise you will end up calling the dummy version!
Notice that the test code in main for Stack and Queue includes some
examples of illegal calls
(addToFront on a Stack, for example). They are there so you can verify
that you have in fact made
those calls illegal. Once you see the resulting compiler errors,
you should comment them out. Once your
Stack and Queue classes work, inspect the output of the test code in
main to make sure you are getting
reasonable output. Data going into the stack should come out
last-in first-out. Data going into the
queue should come out first-in first-out.