#include <iostream>using namespace Std;class Complex{public:complex () {real=0;imag=0;} Complex (double r,double i) {real=r; imag=i;} Complex operator+ (const Complex &C2); Complex operator-(const Complex &C2); Complex operator* (const Complex &C2); Complex operator/(const Complex &C2); void display ();p rivate:double Real; Double imag;};/ /The following defines the member function Complex complex::operator+ (const Complex &C2) {return Complex (REAL+C2.REAL,IMAG+C2.IMAG);} Complex complex::operator-(const Complex &C2) {return Complex (REAL-C2.REAL,IMAG-C2.IMAG);} Complex complex::operator* (const Complex &C2) {return Complex (real*c2.real-imag*c2.imag,real*c2.imag+c2.real* IMAG);} Complex complex::operator/(const Complex &C2) {return Complex ((real*c2.real+imag*c2.imag)/(c2.real*c2.real+ C2.imag*c2.imag), (-REAL*C2.IMAG+C2.REAL*IMAG)/(C2.real*c2.real+c2.imag*c2.imag));} void Complex::d isplay () {if (imag>0) cout<<real<< "+" <<imag<< "I"<<endl; else cout<<real<<imag<< "I" <<ENDL;} The following defines the main () function for testing int main () {Complex C1 (3,4), C2 (5,-10), C3; cout<< "c1="; C1.display (); cout<< "c2="; C2.display (); C3=C1+C2; cout<< "c1+c2="; C3.display (); C3=C1-C2; cout<< "c1-c2="; C3.display (); C3=C1*C2; cout<< "c1*c2="; C3.display (); C3=C1/C2; cout<< "c1/c2="; C3.display (); return 0;}
8th Week Item 1 (1)-Implementing operator overloading in a plural class with member functions