//To demonstrate the Operation of arithmetic assignment (+=)operator overloading.

| |


#include<iostream.h>
#include<conio.h>
 class assignop
 { private:
 int a;
 float b;
 public:
 assignop()
 { a=0;b=0.0;
 }
 assignop(int, float);
 void operator+=(assignop);
 void display();
 };
 assignop::assignop(int n, float m)
 { a=n;
 b=m;
 }
 void assignop::operator+=(assignop obj)
 { a+=obj.a;
 b+=obj.b;
 }
 void assignop::display()
 { cout<<"\na:"<<a;
 cout<<"\nb:"<<b;
 }
 int main()
 { clrscr();
 assignop obj1(1,2.2);
 cout<<"\nContents of first object before addition:";
 obj1.display();
 assignop obj2(3,4.4);
 cout<<"\nContents of second object before addition:";
 obj2.display();
 obj1+=obj2;
 cout<<"\nContents of first object after addition:";
 obj1.display();
 getch();
 return 0;
 }
<