1 #include <iostream> 2 3 using namespace std; 4 5 class complex 6 { 7 private: 8 double real; 9 double image; 10 public: 11 complex(){real=0;image=0;} 12 complex(double a){real=a;image=0;} 13 complex(double a, double b){real=a;image=b;} 14 complex operator+(complex &c) 15 { 16 complex temp; 17 temp.real=this->real+c.real; 18 temp.image=this->image+c.image; 19 return temp; 20 } 21 void show() 22 { 23 cout<<real<<"+j"<<image<<endl; 24 } 25 }; 26 27 int main() 28 { 29 double real1,real2,image1,image2; 30 cin>>real1>>image1; 31 cin>>real2>>image2; 32 complex one(real1,image1); 33 complex two(real2,image2); 34 complex three; 35 three=one+two; 36 one.show(); 37 two.show(); 38 three.show(); 39 return 0; 40 }