AbdulFathaah

add 2 complex return,arguments C++

Dec 12th, 2023 (edited)
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. /*add 2 complex numbers */
  2. #include<iostream.h>
  3. #include<conio.h>
  4.  
  5. class complex //class declaration
  6. {
  7. private : float real;
  8. float imag;
  9. public : void read();
  10. void display();
  11. complex sum(complex);
  12. };
  13. void complex :: read()
  14. {
  15. cout<<"Enter value for real part: ";
  16. cin>>real;
  17. cout<<"Enter value for imaginary part: ";
  18. cin>>imag;
  19. }
  20. complex complex :: sum(complex x)
  21. {
  22. real=real+x.real;
  23. imag=imag+x.imag;
  24. return x;
  25. }
  26. void complex :: display()
  27. {
  28. cout<<real<<"+"<<imag<<"i"<<endl;
  29. }
  30. int main()
  31. {
  32. complex r1,r2,r3;
  33. clrscr();
  34. r1.read();
  35. r2.read();
  36. cout<<"Before Addition:\n";
  37. r1.display();
  38. r2.display();
  39. r3=r1.sum(r2);
  40. cout<<"After Addition:\n";
  41. r1.display();
  42. getch();
  43. return 0;
  44. }
Advertisement
Add Comment
Please, Sign In to add comment