Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ programing Stacks and Queues (.cpp .h) modify this program as follows: 1. Implement it as a dynamic stack (do not use a static stack

C++ programing Stacks and Queues (.cpp .h)

modify this program as follows: 1. Implement it as a dynamic stack (do not use a static stack ). Use a linked list to implement this. 2. Add functionality for Mult, Div, Pop, and Display. 3. Create a looping menu-driven program to demonstrate your code so that the user has the choice of:

1. Push (an integer onto the stack)

2. Pop (an integer off the stack)

3. Add (the top two values in the stack and replace those two values with the sum)

4. Subtract (the top two values on the stack and replace those two values with the difference)

5. Mult (same as above)

6. Div (same as above but check for div by 0)

7. Display Stack

8. End

Make sure you have validation in the mutators. Watch out for division by 0 and not having enough integers on your stack to do the operation. Make sure to only allow integers on your stack. Finally, make sure main() is properly organized into functions and don't forget to document your code including your class.

MathStack.h

// Specification file for the MathStack class

#ifndef MATHSTACK_H #define MATHSTACK_H #include "IntStack.h" class MathStack : public IntStack 7{ public: MathStack(int s) : IntStack(s) {} // Constructor void sub(); // MathStack operations void add(); void add(); }; #endif

MathStack.cpp

#include "MathStack.h" void MathStack::add() { int num, sum;

// Pop the first two values off the stack. pop(sum); pop(num);

// Add the two values, store in sum. sum += num; Push sum back onto the stack. push(sum); }

void MathStack::sub() { int num, diff; // Pop the first two values off the stack. pop(diff); pop(num); // Subtract num from diff. diff ?= num; // Push diff back onto the stack. push(diff); }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

Describe downsizing.

Answered: 1 week ago

Question

Complexity of linear search is O ( n ) . Your answer: True False

Answered: 1 week ago