Sunday, April 11, 2021

simple program using operator overloading (OOP) (66)

#include<iostream>

using namespace std;

class testing

{

private:

int a;

public:

void getdata()

{

cout<<"please enter the number : ";

cin>>a;

}

testing operator +(testing ob1)

{

testing t;

    t.a=a+=ob1.a;

    return t;

}

testing operator +=(testing ob2)

{

testing u;

u.a= a+=ob2.a;

return u;

}

void display()

{

cout<<"the value is: "<<a<<endl;

}

};

int main()

{

testing obj1,obj2,obj3;

obj1.getdata();

obj2.getdata();

cout<<"using + operator";

obj3=obj1+obj2;

obj3.display();

cout<<"using += operator";

obj3=obj1+=obj2;

obj3.display();

} 

No comments:

Post a Comment