Question: Implement a new exception class, StackException, that inherits from std::exception. Your class should include one method: virtual const char * what() const throw(); // Returns

Implement a new exception class, StackException, that inherits from std::exception. Your class should include one method:

virtual const char * what() const throw(); // Returns No items left on stack!

Put your new exception class implementation and header in StackException.cpp and StackException.h, respectively. Finally, write a test program with try-catch to handle this exception in Q2.cpp, and have it print out only your what() method. Write the new stack class in files Q2Stack.cpp and Q2Stack.h. The class name should remain as Stack (not Q2Stack).

c++ code

stack implementation below (This is all the code I have):

void Stack::push(T value)

{

if(size!=40)

{

*elements[size+1] = value;

}

}

template

T Stack::pop()

{

T temp = *elements[--size];

pop();

return temp;

}

template

int Stack::getSize() const

{

return size;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!