Advertisement
fferum

Untitled

Nov 11th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.76 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class complex
  4. {
  5. private:
  6.     int Re = 0;
  7.     int Im = 0;
  8. public:
  9.     complex(int x, int y) {
  10.         Re = x;
  11.         Im = y;
  12.     }
  13.     friend complex operator+(const complex& first, const complex& second) {
  14.         return complex(first.Re + second.Re, first.Im + second.Im);
  15.     }
  16.     int getRe()
  17.     {
  18.         return Re;
  19.     }
  20.     int getIm()
  21.     {
  22.         return Im;
  23.     }
  24. };
  25. int main() {
  26.     int a, b, c, d;
  27.     cout << "Enter first complex (a + bi): " << endl;
  28.     cin >> a >> b;
  29.     cout << "Enter second complex (c + di): " << endl;
  30.     cin >> c >> d;
  31.     complex first(a, b), second(c, d), third = first + second;
  32.     cout << endl << "Result: Re = " << third.getRe() << ", Im = " << third.getIm();
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement