定义一个复数类Complex?
#includeusingnamespacestd;classComplex{private:doublere;doubleim;public:Complex(doublere,doubleim=0){this->re=re;this->im=im;}voidadd(constComplex&c){this->re+=c。 re;this->im+=c。im;}voidsub(constComplex&c){this->re-=c。re;this->im-=c。im;}voidshow(){if(this->re==0)coutimif(this->im==0)coutr...全部
#includeusingnamespacestd;classComplex{private:doublere;doubleim;public:Complex(doublere,doubleim=0){this->re=re;this->im=im;}voidadd(constComplex&c){this->re+=c。
re;this->im+=c。im;}voidsub(constComplex&c){this->re-=c。re;this->im-=c。im;}voidshow(){if(this->re==0)coutimif(this->im==0)coutreif(this->im!=0&&this->imcoutreimif(this->im!=0&&this->im>0)coutreim}};intmain(){doublere,im;cin>>re>>im;Complexc1(re,im);cin>>re;Complexc2=re;c1。
show();c2。show();c1。add(c2);c1。show();c2。sub(c1);c2。show();return0;}。收起