QQWDQD 于 2015.05.31 15:26 提问

4个回答

lzp_lrp      2015.05.31 15:36

guwei4037      2015.05.31 15:52
QQWDQD 这里面好像没求余啊- -
2 年多之前 回复
QQWDQD 这里面好像没求余啊- -
2 年多之前 回复
u012377333   2015.06.01 09:34

cuiwei1026522829      2015.06.02 11:35

#include
using namespace std;
class Complex{
double real;
double imag;
public:
Complex(double r=0,double i=0)
{
real=r;
imag=i;
}
Complex operator+(const Complex& a)
{
Complex b;
b.real=real+a.real;
b.imag=imag+a.imag;
return b;
}
Complex operator-(const Complex& a)
{
Complex b;
b.real=real-a.real;
b.imag=imag-a.imag;
return b;
}
Complex operator*(const Complex& a)
{
Complex b;
b.real=real*a.real-imag*a.imag;
b.imag=real*a.imag+imag*a.real;
return b;
}
Complex operator/(const Complex& a)
{
Complex b,c;
c.real=a.real;
c.imag=-a.imag;
b.real=c.real*a.real-c.imag*a.imag;
b.imag=c.real*b.imag+c.imag*a.real;
return b;
}
friend ostream& operator<<(ostream& os,const Complex& a)
{
if(a.imag >0)
os< else
os return os;
}
friend istream& operator>>(istream&is,Complex& a)
{
is>>a.real;
is>>a.imag;
return is;
}

};

void main()
{
Complex a,b;
Complex c;
cin>>a>>b;
cout<<a<<endl<<b<<endl;
c=a*b;
cout<<c<<endl;
}