#ifndef __complex_h__ #define __complex_h__ #include #include using namespace std; class complex { double re; double im; double m; void refresh_mod() { m = sqrt(re * re + im * im); } public: complex() { re = 0.0; im = 0.0; m = 0.0; } complex(double r) { re = r; im = 0.0; m = r; } complex(double r, double i) { re = r; im = i; refresh_mod(); } complex(const complex & from) { re = from.re; im = from.im; m = from.m; } ~complex() { } void set_real(double r) { re = r; refresh_mod(); } void set_imag(double i) { im = i; refresh_mod(); } void set(double r, double i) { re = r; im = i; refresh_mod(); } double real() const { return re; } double imag() const { return im; } complex operator=(complex from) { re = from.re; im = from.im; m = from.m; return *this; } double mod() const { return m; } complex operator*(complex b) const { return complex(this->re * b.re - this->im * b.im, this->re * b.im + this->im * b.re); } complex operator +=(complex b) { re += b.re; im += b.im; refresh_mod(); return *this; } }; complex operator+(complex a, complex b); ostream & operator <<(ostream & os, complex c); #endif