Question: A stack is a LIFO (last in, first out) data structure. Stacks are extremely useful in programming. A stack can be implemented using an array
A stack is a LIFO (last in, first out) data structure. Stacks are extremely useful in programming. A stack can be implemented using an array to hold values, and a counter to indicate where the "top" item on the stack is. See the first example. (You will need to download the .zip file and decompress it first.) This is a class declaration for a stack of doubles. Store your class declaration in a file called dblstk.h and implement the specified functions exactly as given. You may define whatever private members you think you need. You may also specify additional member functions if you find them useful.
Develop a test program in a file called Stack_driver.cpp for your stack implementation. This driver should define a stack and allow the user to specify, via a menu, the following operations. The user menu should exactly like the following:
1. Display stack 1
2. Place a double value onto the top of stack 1
3. Remove a value from the top of stack 1
4. Check the total capacity stack 1
5. Check current number of items on stack 1
6. Copy stack 1 to stack 2
7. Check to see if the two stacks are equal
8. Quit
Enter menu selection:
Finally, obtain a copy of the instructor's program postfix.cpp; it should be in the downloadable sample source code, as described in Module 1. This program evaluates postfix arithmetic expressions using your stack implementation. Replace your driver module with the postfix.cpp module. The program should run without modification, assuming you have implemented the stack correctly.
Building on the stacks you implemented earlier, add exceptions to the stack class. You should have at least two exceptions: Underflow (popping an empty stack) and Overflow (pushing onto a full stack). Your exceptions should pass along the identity of the stack that caused the exception.
Building on the stacks you implemented in earlier write a generic stack package using templates, so that a user of your package can create stacks of anything.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
