/** [Project 1] implements Operator Overloading in the plural class * Program Copyright and version description Section * copyright (c) 2012, Yantai University Computer college student * All rightsreserved. * file name: object. CPP * siege cainiao: egg * completion date: October 13, April 18, 2013 * version: V1.0 * input Description: Two plural real and virtual parts * Problem description: solution 3: Based on solution 2, extends the functions of the plus (+), minus (-), minus (*), and minus (/) operators to perform operations on double-type data. Set Complex C; double D; C? D and D? The result of C is the result (where? Is + ). In addition, define the objective operator-and-C is equivalent to 0-c. * Program output: Result of the operation using the operator */# include <iostream> Using STD: cout; Using STD: Endl; Class Complex {public: complex () {real = 0; imag = 0;} complex (Double R, double I) {real = r; imag = I;} friend complex operator + (double & D, complex & C2); friend complex operator-(double & D, complex & C2); friend complex operator * (double & D, complex & C2 ); friend complex operator/(double & D, complex & C2); friend complex operator + (complex & C, double & D); friend complex operator-(complex & C, double & D); friend complex operator * (complex & C, double & D); friend complex operator/(complex & C, double & D ); friend complex operator-(complex & C); void display (); Private: Double real; double imag ;}; // The member function complex operator + (double & D, complex & C) {return complex (D + C. real, C. IMAG);} complex operator-(double & D, complex & C) {return complex (d-c.real, C. IMAG);} complex operator * (double & D, complex & C) {return complex (D * C. real, D * C. IMAG);} complex operator/(double & D, complex & C) {return complex (D * C. real/(c. real * C. real + C. imag * C. IMAG),-D * C. imag/(c. real * C. real + C. imag * C. IMAG);} complex operator-(complex & C) {return complex (0-c.real, 0-c.imag);} complex operator + (complex & C, double & D) {return complex (C. real + D, C. IMAG);} complex operator-(complex & C, double & D) {return complex (C. real-D, C. IMAG);} complex operator * (complex & C, double & D) {return complex (C. real * D, C. imag * D);} complex operator/(complex & C, double & D) {return complex (C. real/D, C. imag/d);} void complex: Display () {cout <"(" <real <"," <imag <"I) "<Endl ;}// the test function int main () {double D = 3.14; Complex C (5,-10), C3; cout <"d =" <D <Endl; cout <"c ="; C. display (); C3 = d + C; cout <"d + c ="; c3.display (); C3 = D-C; cout <"D-c = "; c3.display (); C3 = D * C; cout <"D * c ="; c3.display (); C3 = D/C; cout <"d/C = "; c3.display (); C3 = C + D; cout <"C + D ="; c3.display (); C3 = c-d; cout <"c-d = "; c3.display (); C3 = C * D; cout <"C * D ="; c3.display (); C3 = C/d; cout <"C/D = "; c3.display (); C3 =-C; cout <"-c ="; c3.display (); Return 0 ;}