Answer to Question #183054 in C++ for Rocky bhai

Question #183054

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


1
Expert's answer
2021-04-19T19:10:47-0400
#include<iostream>
#include<string.h>
using namespace std;


class STRING
{
        char str[20];
        public:


          void getdata()
        {
             gets(str);


        }


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


                return 0;
        }
};


int main()
{
        STRING s1,s2;


        cout<<"Enter first string :: ";
        s1.getdata();
        cout<<"\nEnter second string :: ";
        s2.getdata();
        if(s1==s2)
        {
            cout<<"\nStrigs are Equal\n";
        }
        else
        {
            cout<<"\nStrings are Not Equal\n";
        }
        
        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
APPROVED BY CLIENTS