// cplex class with all necessary member functions #include class cplex { private: double re; double im; public: cplex (void): re (0.0), im (0.0) { } cplex (double a, double b): re (a), im (b) { } ~cplex (void) { } cplex (const cplex &rhs): re (rhs.re), im (rhs.im) { } const cplex & operator= (const cplex &); cplex operator+ (const cplex &) const; int operator< (const cplex &) const; friend istream & operator>> (istream &, cplex &); friend ostream & operator<< (ostream &, cplex &); }; const cplex & cplex::operator= (const cplex &rhs) // Assignment { if (this != &rhs) { re = rhs.re; im = rhs.im; } return *this; } cplex cplex::operator+ (const cplex & rhs) const // Addition { cplex temp; temp.re = re + rhs.re; temp.im = im + rhs.im; return temp; } istream & operator>> (istream &in, cplex &rhs) // Input { in >> rhs.re >> rhs.im; return in; } ostream & operator<< (ostream &out, cplex &rhs) // Output { out << "(" << rhs.re << ", " << rhs.im << ")"; return out; } int cplex::operator< (const cplex &rhs) const // Compare < { double d1, d2; d1 = sqrt (re*re + im*im); // Determine distances d2 = sqrt (rhs.re*rhs.re + rhs.im*rhs.im); // from (0, 0) return (d1 < d2) ? 1 : 0; }