Friday, 26 January 2018

Implement a string class containing the following functions. -overloaded + operator function to carry out the concatenation of strings. -Overloaded = ( assignment) operator function to carry out string copy. -Function to display the length of a string. -Function to overload comparison operator (= = ) for two strings.

#include<iostream>
using namespace std;

class st
{
    string s1,s2,s3,s4;

    public:
            st(){}
           
            st(string x,string y)
            {
                s1=x;
                s2=y;
            }
           
            void operator +()
            {
                s3=s2+s1;
            }
           
            void operator =(const st &ob1)
            {
                s4=ob1.s2;
            }
           
            bool operator==(st ob1)
            {
                return s1 == ob1.s2;
            }
           
            void display()
            {
                cout<<"\nInput String"<<"\nS1 is: "<<s1<<"\nS2 is:"<<s2;
                cout<<"\nConcated String is: "<<s3;
                cout<<"\nString S4 is: "<<s4;
            }
        };

int main()
{
    st ob("APPLE","APPLE");
    +ob;
    ob=ob;
    ob.display();
   
     if (ob==ob)
     {
        cout << "\na=0";
     }
     else{
        cout << "\na=1";
     }
    return 0;
}

No comments:

Post a Comment

It's time To increase blogging capability. To have a chance to contribute in digital world. Any Interested People who want to make t...