Write a Stack class that will store integers and implement the following methods
ID: 3646420 • Letter: W
Question
Write a Stack class that will store integers and implement the following methods:push
pop
top
isEmpty
Implement the internal storage as a linked list.
(For extra credit, issue an Exception if a pop or top is called on an empty stack.)
You will need to use a driver program, here are the two driver programs I will use to test your classes:
#include "Stack.h"
#include <iostream>
using namespace std;
int main(int argc,char *argv[])
{
try
{
Stack * stack = new Stack();
stack->push(192);
stack->push(45);
stack->push(22);
while (! stack->isEmpty())
{
cout << "Item: " << stack->pop() << endl;
}
cout << "Item: " << "This should Fail: " << stack->pop() << endl;
}
catch (char * exceptionString)
{
cerr << "ERROR!: " << exceptionString << endl;
}
}