#ifndef H_StackType
#define H_StackType
#include <iostream>
#include<cassert>
using namespace std;
//Definition of the template class stackType
template <class Type>
class stackType
{ private :int maxStackSize;
int stackTop;
Type *list;
public :
void initializeStack();
bool isFullStack() const;
bool isEmptyStack() const;
void push( const Type&);
void pop();
Type top() const;
stackType( int = 20 );
~stackType();
bool operator==( conststackType<Type>&);
};
template <class Type>
void stackType<Type>::initializeStack()
{
stackTop = 0;
}
template <class Type>
bool stackType<Type>::isFullStack() const
{
return ( stackTop == maxStackSize );
}
template <class Type>
bool stackType<Type>::isEmptyStack() const
{
return ( stackTop == 0 );
}
template <class Type>
void stackType<Type>::push( const Type&newItem )
{
if ( !isFullStack() )
{
list[ stackTop ] = newItem;
stackTop++;
}else
cout << "ntCan not add to a full stack";
}
template <class Type>
void stackType<Type>::pop()
{
if ( !isEmptyStack() )
stackTop--;
else
cout << "ntCan not remove from an empty stack";
}
template <class Type>
Type stackType<Type>::top() const
{
assert( stackTop != 0 );
return list[ stackTop - 1 ];
}
template <class Type>
stackType<Type>::stackType( int stackSize )
{
if ( stackSize <= 0 )
{
cout << "Invalid size";
stackSize = 10;
}else
maxStackSize = stackSize;
stackTop = 0;
list = new Type[ maxStackSize ];
}
template <class Type>
stackType<Type>::~stackType()
{
delete[] list;
}
template <class Type>
bool stackType<Type>::operator==( const stackType<Type>&right )
{
if (this->stackTop != right.stackTop )
return false;
for ( int i = 0; i < stackTop; i++)
if ( this->list[ i ] != right.list[ i ] )
return false;
return true;
}
#endif
intmain()
{
cout << "nntProgram to overload the realtional" << "operator == for the class stackType.";
stackType<int> s1( 12 );
stackType<int> s2( 15 );
cout << "nntInserting elements 5, 10, 15 ... "<< "to both the stacks.";
for ( int i = 5; i < 50; i+=5 )
{
s1.push( i );
s2.push( i );
}
if ( s1 == s2 )
cout << "ntBoth the stacks are equal";
else
cout << "ntBoth the stacks are not equal";
cout<<"ntInserting element 11 to the secondstack.";
s2.push( 11 );
if ( s1 == s2 )
cout << "ntBoth the stacks are equal";
else
cout << "ntBoth the stacks are not equal";
cout << "nnt";
system("pause");
return 0;
}I hope this will helps to You!C++ myStack.lh stackADT.h Instructions main.cpp 1 #include«iostream» 2 #include<stdlib.h> 3 #include«conio.h> 4 #include«ostream» 5 using namespace std; 6 const int SIZE-5; //Stack size 7 //class declaration 8 class stack 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 operatorfor the class stackType that returns true if two stacks of the same type are the same; it returns false...
(C++) 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 classstackType. **Please...
C++ Please ensure code is fully working, will rate Question to be answered: Repeat Exercise 1 for the class linkedStackType question one: 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, false otherwise. Also, write the definition...
Overload a relational operator for the Job class: Assume that this operator is not overloaded for the Salary class. a) Write how the function will be declared in your code. b) Write an external function definition (not inside the class). solve it in C++10 to solve this you nedd question number 1. Create a composition between the classes Job and Salary. Class Salary a. data member: 1. money b. constructors: 1. default constructor 2. user defined constructor with a parameter...
C++ This chapter uses the class rectangleType to illustrate how to overload the operators +, *, ==, !=, >>, and <<. In this exercise, first redefine the class rectangleType by declaring the instance variables as protected and then overload additional operators as defined in parts 1 to 3. Overload the pre- and post-increment and decrement operators to increment and decrement, respectively, the length and width of a rectangle by one unit. (Note that after decrementing the length and width, they...
Use C++! This program uses the class myStack to determine the highest GPA from a list of students with their GPA.The program also outputs the names of the students who received the highest GPA. Redo this program so that it uses the STL list and STL queue! Thank you! HighestGPAData.txt* 3.4 Randy 3.2 Kathy 2.5 Colt 3.4 Tom 3.8 Ron 3.8 Mickey 3.6 Peter 3.5 Donald 3.8 Cindy 3.7 Dome 3.9 Andy 3.8 Fox 3.9 Minnie 2.7 Gilda 3.9 Vinay...
Create a class or struct called Display. The class or struct should overload the operator() function and accept an integer and displays that argument value. (C++)
Create a class or struct called Display. The class or struct should overload the operator() function and accept an integer and displays that argument value. (C++)
/* FILE NAME: Class{aSet}.cpp FUNCTION: A template class for a set in C++. It implements all the set operations, except set compliment: For any two sets, S1 and S2 and an element, e A. Operations which result in a new set: (1) S1 + S2 is the union of S1 and S2 (2) S1 - S2 is the set difference of S1 and S2, S1 - S2 (3) S1 * S2 is the set intersection of S1 and S2, S1 * S2 (4) S1 + e (or e +...
QUESTION 18 According to class materials, the program is allowed to overload operators only if at least one incoming parameter received by the operator has a class type. 1. (a) True 2. (b) False QUESTION 19 According to the course materials, a function can take value parameters and reference parameters. A value parameter is a separate variable from the one in main() or another calling function only if the function value parameter has a different name than the one in...