Homework Help Question & Answers

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

C++

myStack.lh stackADT.h Instructions main.cpp 1 #include«iostream» 2 #include<stdlib.h> 3 #include«conio.h> 4 #include«ostream»

myStack.lh stackADT.h Instructions main.cpp 1 #include«iostream» 2 #include 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 otherwise. 10 int items SIZE 11 int top; 12 int full(); 13 int empty(); 14 public: 15 stack() 16 17 top -1; 18 19 stack operator--(int); 20 friend stack operator (stack s1,int elem); 21 bool operator(stack &); 22 friend ostream &operator
0 0
Next > < Previous
ReportAnswer #1

#include<bits/stdc++.h>
using namespace std;
#define limit 1000
class Stack
{
int top;
public:
int stack[limit];
Stack()
{
top=0;
}
void push(int x) //push operation
{
if(top >= (limit))
{
cout << "Stack Overflow";
}
else
{
stack[top] = x;
top++;
}
}
int pop() // pop opertaion
{
if(top<=0)
{
cout<<"Stack Underflow";
}else
{
int r;
top--;
r=stack[top];
return r;
}
}
bool operator == (Stack &s2) //overload == operator
{
if(top!=s2.top) // if size not equal than stack are not same
{
return false;
}else
{
for(int i=0;i<top;i++)
{
if(stack[i]!=s2.stack[i]) /* if at any index element not same stack are not equal*/
{
return false;
}
}
return true;
}

}
};
int main()
{
Stack s;
s.push(10);
s.push(20);
s.push(30);
Stack s1;
s1.push(10);
s1.push(20);
s1.push(30);
if(s==s1)
{
cout<<"Stack are same";
}else
{
cout<<"Stack are not same";
}
return 0;
}

/*

Output:-

Stack are same

*/

Know the answer?
Add Answer of:
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 //...
Your Answer: Your Name: What's your source?
Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Data Structures Using C++

    1. 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 therelational operator == for the class stackType that returns true if two stacks of the same type are the same, false otherwise. Also, write the definition of thefunction template to overload this operator.2. Repeat exercise 1 for the class linkedStackType.3. A. Add the following operation to the class stackType:void reverseStack(stackType<Type> &otherStack);This...

  • 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 t...

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

  • some one help me to correct this c++ code please( lifesaver )

    x.øi5Create the following string class definition which may be used to store a table of strings,class Strtable { friend ostream &operator<<( ostream &, const Strtable&); friend istream &operator>>( istream &, Strtable&); public: Strtable ( int = 10 ) ; //default constructor. Theparameter of the// constructor is used to initialize the private member size. ~Strtable ( ) ; const char *operator[](int); bool operator+(const char *); bool operator==(const char *);Strtable &operator+=(const Strtable &); private: intsize; // max. number of strings that may...

  • C++ LinkedList I need the code for copy constructor and assignment operator #include <iostream> #include <string> using namespace std; typedef string ItemType; struct Node {    ItemType va...

    C++ LinkedList I need the code for copy constructor and assignment operator #include <iostream> #include <string> using namespace std; typedef string ItemType; struct Node {    ItemType value;    Node *next; }; class LinkedList { private:    Node *head;    // You may add whatever private data members or private member functions you want to this class.    void printReverseRecursiveHelper(Node *temp) const; public:    // default constructor    LinkedList() : head(nullptr) { }    // copy constructor    LinkedList(const LinkedList& rhs);    // Destroys all the dynamically allocated memory    //...

  • The stack ADT using an array-based data structure

    This program is an exercise in implementing the stack ADT using an array-based data structure.This program creates and implements a class to represent the Stack ADT using an array.A driver program is provided for this program to test the implementation. No need to write the tests.ProgramYou will need to write a single class for this program, the Stack class. You will need to implement several methods and functions associated with this class.The class should be implemented as two separate files....

  • //Look for** to complete this program --C+ please --please add comments // using namespace std; #include...

    //Look for** to complete this program --C+ please --please add comments // using namespace std; #include <iostream> #include <stdlib.h> #include < string> #include "queue.h" //Purpose of the program: ** Algorithm: * int main() /** "A", "B", "C" in the queue //** while loop -- indefinitely { try {//** catches } //* end of loop } |/ II II II II II //File type: ** queue.cpp using namespace std; #include <iostream> #include "queue.h" // constructor queue::queue () } //destructor queue::~queue() queue::queue...

  • Simple Questions - *Urgent* C++ Programming by Malik Chapter 15 PE 18 (5th Ed) Follow-up

    I posed this question earlier and got the following code, which didn't compile. First, would like to know which part of this is step c? If it could be isolated andcorrected, I'd really appreciate it - need it tomorrow (yikes!) I can be more specific about the question if you send a private message if you don't have the book.(Group project - don't want to sink the other students!) Thank you.#ifndef H_myString#define H_myString#includeusing namespace std;class newString{//overload the stream insertion and...

  • C++ programing using C-tyle

    x.øi5="left">Create a user-defined Abstract Data Type (ADT) that implements a stack using a C++ class named Stack• The Stack ADT must be implemented using a dynamic array.• Each element stored in the Stack ADT is of type Element.o Element is an exportable C-style string data type that supports a maximum of 12 characters.The Stack ADT must define and implement the following data types and operations.Do not add any additional data types or operations.Do not modify any of the defined data...

  • Stack C++. Please Help!! Running out of time..

    Task: Modify the provided Stack to store integers instead of characters. Use themodified stack to implement a RPN calculator. Output an appropriate error message if there are not two operands on the stack when given an operator. Use a loop toprocess an RPN expression, one operator/operand at a time, until a ‘q’ is entered. When the ‘q’ is entered, print the top of the stack (it contains the solution)and either exit the program or ask the user if he/she wants...

  • SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! myst...

    SCREENSHOTS ONLY PLEASE!!! DON'T POST ACTUAL CODE PLEASE LEAVE A SCREENSHOT ONLY! ACTUAL TEXT IS NOT NEEDED!!! mystring.h: //File: mystring1.h // ================ // Interface file for user-defined String class. #ifndef _MYSTRING_H #define _MYSTRING_H #include<iostream> #include <cstring> // for strlen(), etc. using namespace std; #define MAX_STR_LENGTH 200 class String { public: String(); String(const char s[]); // a conversion constructor void append(const String &str); // Relational operators bool operator ==(const String &str) const; bool operator !=(const String &str) const; bool operator >(const...

Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
Share Your Knowledge

Post an Article
Post an Answer
Post a Question with Answer

Self-promotion: Authors have the chance of a link back to their own personal blogs or social media profile pages.