#ifndef __COMPLEX_H__ #define __COMPLEX_H__ // prevent multiple inclusion #include // access: ostream // NO "using namespace std", use qualification to prevent polluting user's namespace class Complex { friend Complex operator+( Complex a, Complex b ); friend Complex operator-( Complex a, Complex b ); friend Complex operator*( Complex a, Complex b ); friend Complex operator/( Complex a, Complex b ); friend bool operator==( Complex a, Complex b ); friend bool operator!=( Complex a, Complex b ); friend std::istream &operator>>( std::istream &is, Complex &c ); friend std::ostream &operator<<( std::ostream &os, Complex c ); double re, im; // exposed implementation static int cplxObjCnt; // shared counter public: Complex( double r = 0.0, double i = 0.0 ); // default values only in prototype double real() const; // const means argument object immutable double imag() const; Complex conjugate() const; double abs() const; static void stats(); // no "this" }; extern Complex operator+( Complex a, Complex b ); // allow implicit conversions on both operands extern Complex operator-( Complex a, Complex b ); extern Complex operator*( Complex a, Complex b ); extern Complex operator/( Complex a, Complex b ); extern bool operator==( Complex a, Complex b ); extern bool operator!=( Complex a, Complex b ); // complex field is unordered so no relational operators, e.g. <, >, <=, >= extern std::istream &operator>>( std::istream &is, Complex &c ); extern std::ostream &operator<<( std::ostream &os, Complex c ); #endif // __COMPLEX_H__