Answer to Question #193425 in C++ for Sarivinkumar M

Question #193425

Create a 'STRING' class which overloads ‘= = ' operator to compare two STRING objects


1
Expert's answer
2021-05-18T02:50:50-0400
/*  
    *C++ Program that compares tow stirngs using operator overloading  
*/


#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;


class STRING
{
    char str[20];
    public:
    //Read user input
    void getdata()
    {
         gets(str);


    }


    //Overload the operator
    int operator ==(STRING s)
    {
       if(!strcmp(str,s.str))
        return 1;


        return 0;
    }
};
//Driver program
int main()
{
    STRING s1,s2;


    cout<<"Enter first string :";
    s1.getdata();
    
    cout<<"Enter second string :";
    
    s2.getdata();
    
    if(s1==s2)
    {
        cout<<"Strigs are Equal"<<endl;
    }
    else
    {
        cout<<"Strings are Not Equal"<<endl;
    }
    
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog