Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*program to overload bianry operator +*/
- #include<iostream.h>
- #include<conio.h>
- class Sum //class declaration
- {
- private : int a;
- public : void read();
- void display();
- Sum operator+(Sum);
- };
- void Sum :: read()
- {
- cout<<"Enter value : ";
- cin>>a;
- }
- Sum Sum :: operator+(Sum x)
- {
- Sum s3;
- s3.a=a+x.a;
- return s3;
- }
- void Sum :: display()
- {
- cout<<"Sum= "<<a<<endl;
- }
- int main()
- {
- Sum s1,s2,s3;
- clrscr();
- s1.read();
- s2.read();
- s3=s1+s2;
- cout<<"After Addition:\n";
- s3.display();
- getch();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment