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 }
重载加法运算符的复数运算 代码参考
猜你喜欢
转载自www.cnblogs.com/Conan-jine/p/12800495.html
今日推荐
周排行