Program code:
# Include
Using namespace std; class Complex {public: Complex () // defines the default constructor initialization plural {real = 0; imag = 0 ;} // use the initialization table to initialize the Complex (double r, double I): real (r), imag (I) {} Complex operator + (Complex & c2 ); // Complex addition Complex operator-(Complex & c2); // Complex subtraction Complex operator * (Complex & c2 ); // multiplication of the Complex number Complex operator/(Complex & c2); // division of the Complex number void display (); // display the Complex number private: double real; // real-part double imag of the plural number; // virtual part of the plural number}; // addition of the plural number Complex: operator + (Complex & c2) {Complex c3; c3.real = real + c2.real; c3.imag = imag + c2.imag; return c3;} // subtraction of Complex numbers Complex: operator-(Complex & c2) {Complex c3; c3.real = real-c2.real; c3.imag = imag-c2.imag; return c3;} // multiplication of Complex numbers Complex: operator * (Complex & c2) {Complex c3; c3.real = real * c2.real-imag * c2.imag; c3.imag = real * c2.imag + imag * c2.real; return c3;} // division of Complex numbers Complex: operator/(Complex & c2) {Complex c3; c3.real = (real * c2.real + imag * c2.imag)/(c2.real * c2.real + c2.imag * c2.imag); c3.imag = (imag * c2.real-real * c2.imag) /(c2.real * c2.real + c2.imag * c2.imag); return c3;} // display the plural void Complex: display () {cout <
Execution result: