In labs 13 and 14 you created a priority queue that was derived from vector. The queue held instances of qElem and allowed you to sort the queue based on the priority.

For this assignment you are to create a Stack class that is also derived from vector. Your Stack should work like the queue in that it will hold instances of qElem. This is the same element that you used for the queue class. In this instance we are not goiong to be using the int that holds the priority but we are reserving the space in the case we need to create a priority stack derived from our stack class.

Your stack should allow you to create a stack of any type.

Stack iStack; // Holds ints
Stack sStack

Your stack should have the following functionality:

  • push - Add an element to the top of the stack
  • pop - Return the value at the top of the stack and remove it
  • peek - Return a value at the top of the stack. Do not remove it

Operator overloads. You should also implement the following operator overloads.

  • += - pushes an element on the stack
  • -= - pops a value from the top of the stack. Note this pop will not return the element it simply removes it. To see the value you would use peek before calling -=

Specifics. You should use the qElem struct that you created in labs 13 and 14. This struct should be a template type so that it can hold a value of any type.

The Stack should be derived from vector and should also be a template class so that it can operate on any type

Handling Errors. You should create a StackError class that has a string as the data section to hold the reason the error was thrown. You should throw an error under the following conditions

  • Trying to peek with an empty stack
  • Trying to pop with an empty stack

Make sure the error message thrown is appropriate. Some thing like "Empty Stack" should be sufficient.

For this assignment it is important that you understand inheritance and to use it properly.

Academic Honesty!
It is not our intention to break the school's academic policy. Projects posted are only used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly fill out the form. Please provide a valid email address and we'll get back to you in less than 24 hours. We will be sending an invoice through PayPal upon confirmation. We are a non profit organization however we need an amount to keep this organization running, and to be able to complete our research and development.