// ---------- // complexx.h // ---------- // Project 2 of Com S 229 // Due at 11:59pm on Wednesday, Oct 5, 2011 // // Implement the following class. #include #include using namespace std; const double pi = 3.14159265358979323846; const double epsilon = 0.00001; class complex { public: complex (double x = 0.0, double y = 0.0); // constructor // access member functions double realPart() const; // return real part double imagPart() const; // return imaginary part double magnitude() const; // return magnitude double phase() const; // return phase complex sqrt() const; // square root with nonnegative real part complex pow(int n) const; // nth power, more efficiently implemented using magnitude and // phase angle. complex operator+ (const complex& rhs); // complex addition complex operator- (const complex& rhs); // complex subtraction complex operator* (const complex& rhs); // complex multiplication complex operator/ (const complex& rhs); // complex division bool operator== (const complex& rhs); // equality complex operator-() const; // negation of a complex number friend ostream& operator<< (ostream& ostr, const complex& x); // see Section 3.1 of hw2-project.pdf friend istream& operator>> (istream& istr, complex& x); // for input/output formats. private: double real; // real part double imag; // imaginary part }; // evaluate the polynomial f(z) = z^8 - 170 z^6 + 7392 z^4 - 39712 z^2 + 51200 complex f(const complex& z);