Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class complex
- {
- private:
- int Re = 0;
- int Im = 0;
- public:
- complex(int x, int y) {
- Re = x;
- Im = y;
- }
- friend complex operator+(const complex& first, const complex& second) {
- return complex(first.Re + second.Re, first.Im + second.Im);
- }
- int getRe()
- {
- return Re;
- }
- int getIm()
- {
- return Im;
- }
- };
- int main() {
- int a, b, c, d;
- cout << "Enter first complex (a + bi): " << endl;
- cin >> a >> b;
- cout << "Enter second complex (c + di): " << endl;
- cin >> c >> d;
- complex first(a, b), second(c, d), third = first + second;
- cout << endl << "Result: Re = " << third.getRe() << ", Im = " << third.getIm();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement