HOMEWORK 6
Due: December 4th before class. NO LATE SUBMISSIONS.
Techniques: Templates
Build a template stack class (DO NOT USE THE STANDARD C++ STACK CLASS ) that will support the following functions:
A current image of an integer stack maybe :
2 ß top
3
4
7
8
3
1 ß bottom
empty() will return false
size() should return 7
pop() will give you
3 ß top
4
7
8
3
top will return 3
push(10) will return the following stack:
10 ß top
3
4
7
8
3
1 ß bottom
top() followed by a pop() will return AND remove the top most element of the stack.
Output: In your main(), create at least two kinds of stacks ( say a stack that contains integers and strings. Note that C++ now has a built in string class ).
Populate your stack class with some values by using push(). Print out the stack. Then perform some pop(), top() and push functions randomly, printing the stack after each such operation. Remember to take care of popping and empty stack. Your program should flag an error in such a case.
Also the size of the array should be entered via a constructor. A call to push() should check if the size of the stack is getting violated or not.
Also remember to write a destructor which will delete the objects if you are using dynamic arrays in the template class.