Question: In c + + need help with main.cpp Instructions Two stacks of the same type are the same if they have the same number of

In c++ need help with main.cpp
Instructions
Two stacks of the same type are the same if they have the same number of elements and their elements at the corresponding positions are the same.
Overload the relational operator == for the class stackType that returns true if two stacks of the same type are the same; it returns false otherwise.
Also, write the definition of the function template to overload this operator.
Write a program to test the various overloaded operators and functions of class stackType.
main.cpp
#include
#include "myStack.h"
using namespace std;
int main(){
return;
}
myStack.h
#ifndef H_StackType
#define H_StackType
#include
#include
#include "stackADT.h"
using namespace std;
template
class stackType: public stackADT
{
public:
const stackType& operator=(const stackType&);
void initializeStack();
bool isEmptyStack() const;
bool isFullStack() const;
void push(const Type& newItem);
Type top() const;
void pop();
stackType(int stackSize =100);
stackType(const stackType& otherStack);
~stackType();
bool operator==(const stackType& otherStack) const;
private:
int maxStackSize;
int stackTop;
Type *list;
void copyStack(const stackType& otherStack);
};
template
void stackType::initializeStack()
{
stackTop =0;
}
template
bool stackType::isEmptyStack() const
{
return(stackTop ==0);
}
template
bool stackType::isFullStack() const
{
return(stackTop == maxStackSize);
}
template
void stackType::push(const Type& newItem)
{
if (!isFullStack())
{
list[stackTop]= newItem;
stackTop++;
}
else
cout << "Cannot add to a full stack." << endl;
}//end push
template
Type stackType::top() const
{
assert(stackTop !=0);
return list[stackTop -1];
}
template
void stackType::pop()
{
if (!isEmptyStack())
stackTop--;
else
cout << "Cannot remove from an empty stack." << endl;
}
template
stackType::stackType(int stackSize)
{
if (stackSize <=0)
{
cout << "Size of the array to hold the stack must "
<<"be positive." << endl;
cout << "Creating an array of size 100."<< endl;
maxStackSize =100;
}
else
maxStackSize = stackSize;
stackTop =0;
list = new Type[maxStackSize];
}
template
stackType::~stackType()
{
delete [] list;
}
template
void stackType::copyStack(const stackType& otherStack)
{
delete [] list;
maxStackSize = otherStack.maxStackSize;
stackTop = otherStack.stackTop;
list = new Type[maxStackSize];
for (int j =0; j < stackTop; j++)
list[j]= otherStack.list[j];
}
template
stackType::stackType(const stackType& otherStack)
{
list = nullptr;
copyStack(otherStack);
}
template
const stackType& stackType::operator=
(const stackType& otherStack)
{
if (this != &otherStack)
copyStack(otherStack);
return *this;
}
#endif
stackADT.h
#ifndef H_StackADT
#define H_StackADT
template
class stackADT
{
public:
virtual void initializeStack()=0;
virtual bool isEmptyStack() const =0;
virtual bool isFullStack() const =0;
virtual void push(const Type& newItem)=0;
virtual Type top() const =0;
virtual void pop()=0;
};
#endif

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!