AbdulFathaah

sum op overloading w/o return C++

Dec 19th, 2023 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.52 KB | None | 0 0
  1. /*program to overload bianry operator +*/
  2. #include<iostream.h>
  3. #include<conio.h>
  4.  
  5. class Sum //class declaration
  6. {
  7. private : int a;
  8. public : void read();
  9. void display();
  10. void operator+(Sum);
  11. };
  12. void Sum :: read()
  13. {
  14. cout<<"Enter value : ";
  15. cin>>a;
  16. }
  17. void Sum :: operator+(Sum x)
  18. {
  19. a=a+x.a;
  20. }
  21. void Sum :: display()
  22. {
  23. cout<<"Sum= "<<a<<endl;
  24. }
  25. int main()
  26. {
  27. Sum s1,s2,s3;
  28. clrscr();
  29. s1.read();
  30. s2.read();
  31. s1+s2;
  32. cout<<"After Addition:\n";
  33. s1.display();
  34. getch();
  35. return 0;
  36. }
Advertisement
Add Comment
Please, Sign In to add comment