You are viewing a single comment's thread. Return to all comments →
My solution:
Complex operator+(const Complex & X, const Complex & Y) { Complex Z {X.a + Y.a, X.b + Y.b}; return Z; } ostream & operator<< (ostream & out, const Complex & X) { if (X.b < 0) { out << X.a << "-i" << -X.b; } else if(X.b > 0) { out << X.a << "+i" << X.b; } else { out << X.a; } return out; }
It wasn't clear what we ought to do in the case that the imaginary part was 0, so I chose to print out only the real part in that case.
Seems like cookies are disabled on this browser, please enable them to open this website
Overload Operators
You are viewing a single comment's thread. Return to all comments →
My solution:
It wasn't clear what we ought to do in the case that the imaginary part was 0, so I chose to print out only the real part in that case.