Advertisement
Guest User

Untitled

a guest
Apr 1st, 2020
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.29 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Complex {
  5. public :
  6. double re, im;
  7. Complex(double r = 0, double i = 0) {
  8. re = r, im = i;
  9. }
  10. void citire() {
  11. cout << "Re = "; cin >> re;
  12. cout << "Im = "; cin >> im;
  13. }
  14. void afisare() {
  15. cout << "Partea reala : " << re << " Partea imaginara = " << im << "\n";
  16. }
  17. friend Complex operator+(Complex, Complex); // ????
  18. };
  19.  
  20. Complex operator+(Complex a, Complex b) {
  21. Complex z;
  22. z.re = a.re + b.re;
  23. z.im = a.im + b.im;
  24. return z;
  25. }
  26.  
  27. Complex operator-(Complex a, Complex b) {
  28. Complex z;
  29. z.re = a.re - b.re;
  30. z.im = a.im - b.im;
  31. return z;
  32. }
  33.  
  34. Complex operator*(Complex a, Complex b) {
  35. Complex z;
  36. z.re = (a.re * b.re) - (a.im * b.im);
  37. z.im = (a.re * b.im + b.re * a.im);
  38. return z;
  39. }
  40.  
  41. int main() {
  42. Complex z1, z2;
  43. z1.citire();
  44. z2.citire();
  45. cout << "z1 : ";
  46. z1.afisare();
  47. cout << "z2 : ";
  48. z2.afisare();
  49. cout << "z1 + z2 : ";
  50. Complex z3;
  51. z3 = z1 + z2;
  52. z3.afisare();
  53. Complex z4;
  54. z4 = z1 - z2;
  55. cout << "z1 - z2 : ";
  56. z4.afisare();
  57. Complex z5;
  58. z5 = z1 * z2;
  59. cout << "z1 * z2 : ";
  60. z5.afisare();
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement