Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use the stackADT class and stackType classes given to you in Ch. 18 and code supplied here to complete this assignment. #include #include myStack.h using

Use the stackADT class and stackType classes given to you in Ch. 18 and code supplied here to complete this assignment.

#include

#include "myStack.h"

using namespace std;

int main()

{

stackType stack1(50);

stackType stack2(50);

stack1.initializeStack();

stack1.push(23);

stack1.push(45);

stack1.push(38);

stack2 = stack1;

if (stack1 == stack2)

cout << "stack1 and stack2 are identical" << endl;

else

cout << "stack1 and stack2 are not identical" << endl;

stack2.pop();

stack2.push(32);

cout << "**** After pop and push operations on stack2 ****" << endl;

if (stack1 == stack2)

cout << "stack1 and stack2 are identical" << endl;

else

cout << "stack1 and stack2 are not identical" << endl;

stack2.push(11);

cout << "**** After another push operation on stack2 ****" << endl;

if (stack1 == stack2)

cout << "stack1 and stack2 are identical" << endl;

else

cout << "stack1 and stack2 are not identical" << endl;

return 0;

}

Modify the stack implementation such that it uses a vectors as the container instead of an array.

Overload the pure virtual function push such that it takes a vector as an argument which pushes multiple values onto the stack.

Throw exceptions when:

An attempt is made to pop from an empty stack (display message)

An attempt is made to push onto a full stack (display message)

top() is called on an empty stack (display message).

A negative or zero value for stack size is passed to the constructor (In this case, when handling the error, automatically recall the constructor with a value of 100).

Using the STL queue container, add multiple stackType classes to a queue. Demonstrate an ability to use STL queue methods such as front() and pop().

Useful notes:

Leverage the functions which are already given to you.

Submission requirements:

Submit all files required to make this program run as required. Your solution can be a single file.

Submit source code, a screenshot with a time stamp of code execution, and a text file of the code. All code should include comments.

Code 1

template class stackADT { public: virtual void initializeStack() = 0; //Method to initialize the stack //Postcondition: Stack is empty. to an empty state. virtual bool isEmptyStack() const = //Function to determine whether the stack is empty. //Postcondition: Returns true if the stack is empty, 0; // otherwise returns false. virtual bool isFullStack() const = 0; //Function to determine whether the stack is full. //Postcondition: Returns true if the stack is full, // otherwise returns false. virtual void push(const Type& newItem) = 0; //Function to add newItem to the stack. //Precondition: The stack exists and is not full. The stack is changed and newItem is added to the top of the stack. virtual Type top() //Function to return the top element of the stack. //Precondition: The stack exists and is not empty. //Postcondition: // const = 0; //Postcondition: // // If the stack is empty, the program terminates; otherwise, the top element of the stack is returned. = 0; };

Code 2

template class stackType: public stackADT { public: const stackType& operator=(const stackType&); //Overload the assignment operator. void initializeStack(); //Function to initialize the stack to an empty state. //Postcondition: stackTop = 0 bool isEmptyStack() const; //Function to determine whether the stack is empty. //Postcondition: // Returns true if the stack is empty, otherwise returns false. bool isFullStack() //Function to determine whether the stack is full. //Postcondition: Returns true if the stack is full, // otherwise returns false.

void push(const Type& newItem); //Function to add newItem to the stack. //Precondition: The stack exists and is not full. //Postcondition: The stack is changed and newItem // is added to the top of the stack. Type top() const; //Function to return the top element of the stack. //Precondition: The stack exists and is not empty. //Postcondition: If the stack is empty, the program // terminates; otherwise, the top element // of the stack is returned. void pop(); //Function to remove the top element of the stack. //Precondition: The stack exists and is not empty. //Postcondition: The stack is changed and the top // element is removed from the stack. stackType(int stackSize = 100); //Constructor //Create an array of the size stackSize to hold //the stack elements. The default stack size is //Postcondition: The variable list contains the // address of the array, stackTop // maxStackSize = stackSize. stackType(const stackType& otherStack); //Copy constructor ~stackType(); 100. base = 0, and //Destructor //Remove all the elements from the stack. //Postcondition: The array (list) holding the stack // elements is deleted. private: int maxStackSize; //variable to store the maximum stack size int stackTop; //variable to point to the top of the stack Type *list; //pointer to the array that holds the //stack elements void copyStack(const stackType& otherStack); //Function to make a copy of otherStack. //Postcondition: A copy of otherStack is created and // assigned to this stack. };

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

Oracle Database Upgrade Migration And Transformation Tips And Techniques

Authors: Edward Whalen ,Jim Czuprynski

1st Edition

0071846050, 978-0071846059

More Books

Students also viewed these Databases questions

Question

Is there a clear hierarchy of points in my outline?

Answered: 1 week ago