C++复数加减乘除的实现#includeiostreamusingnamespacestd;classComplex{public:Complex(){real=0;imag=0;}Complex(doubler,doublei){real=r;imag=i;}Complexoperator+(Complex&c2);Complexoperator-(Complex&c2);Complexoperator*(Complex&c2);Complexoperator/(Complex&c2);voiddisplay();private:doublereal;doubleimag;};ComplexComplex::operator+(Complex&c2){Complexc;c.real=real+c2.real;c.imag=imag+c2.imag;returnc;}ComplexComplex::operator-(Complex&c2){Complexc;c.real=real-c2.real;c.imag=imag-c2.imag;returnc;}ComplexComplex::operator*(Complex&c2){Complexc;c.real=real*c2.real-imag*c2.imag;c.imag=imag*c2.real+real*c2.imag;returnc;}ComplexComplex::operator/(Complex&c2){Complexc;c.real=(real*c2.real+imag*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag);c.imag=(imag*c2.real-real*c2.imag)/(c2.real*c2.real+c2.imag*c2.imag);returnc;}voidComplex::display(){cout(real,imagi)endl;}intmain(){Complexc1(3,4),c2(5,-10),c3;c3=c1+c2;coutc1+c2=;c3.display();c3=c1-c2;coutc1-c2=;c3.display();c3=c1*c2;coutc1*c2=;c3.display();c3=c1/c2;coutc1/c2=;c3.display();return0;}