Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

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;

}

}

Explanation / Answer

#include #include using namespace std; int main() { string title; int howmany; stack discs; //Asking the user how many discs he wants to enter in the stack. //The loop will rotate that many number of times and then //prompt the user for input. couthowmany; for(int i=0;i>title; //pushing the discs one upon the other discs.push(title); } cout
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote