Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

task:

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:

stackTop = 0;

} // end function initializeStack

// check for stack fullness

template

bool stackType::isFullStack() const

{

return ( stackTop == maxStackSize );

} // end function isFullStack

// check for stack empty

template

bool stackType::isEmptyStack() const

{

return ( stackTop == 0 );

} // end function isEmptyStack

// insert an element into stack

template

void stackType::push( const Type& newItem )

{

if ( !isFullStack() )

{

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&);

//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() const;

//Function to determine whether the stack is full.

stackATD.h:

#ifndef H_StackADT

#define H_StackADT

template

class stackADT

{

public:

virtual void initializeStack() = 0;

//Method to initialize the stack to an empty state.

//Postcondition: Stack is empty

virtual bool isEmptyStack() const = 0;

//Function to determine whether the stack is empty.

//Postcondition: Returns true if the stack is empty,

// 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.

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

Database In Depth Relational Theory For Practitioners

Authors: C.J. Date

1st Edition

0596100124, 978-0596100124

More Books

Students also viewed these Databases questions

Question

Write a letter asking them to refund your $1,500 down payment.

Answered: 1 week ago