#include"fushu.h"
fushu::fushu()
{
real= 0 ;
imag= 0 ;
}
fushu::fushu( double _real, double _imag)
{
real=_real;
imag=_imag;
}
fushu operator+(const fushu & p,const fushu & q)
{
fushu m=fushu(p.real+q.real,p.imag+q.real);
return m;
}
fushu operator-(const fushu & p,const fushu & q)
{
fushu m=fushu(p.real-q.real,p.imag-q.imag);
return m;
}
fushu operator*(const fushu & p,const fushu & q)
{
fushu m=fushu(p.real*q.real-p.imag*q.imag,p.real*q.imag+q.real*p.imag);
return m;
}
fushu operator/(const fushu & p,const fushu & q)
{
fushu m=fushu((p.real*q.real+p.imag*q.imag)/(p.real*p.real+q.imag*q.imag),(p.real*q.imag-q.real*p.imag)/(p.real*p.real+q.imag*q.imag));
return m;
}
ostream & operator<<(ostream & o, const fushu & p)
{
if ( p.imag==0 )
o<<p.real<<endl ;
else if(p.real==0)
o<<p.imag<<"i\n";
else
o<<p.real<<"+("<<p.imag<<"i)\n" ;
return o ;
}
void operator>>(istream & i, fushu &p)
{
cout<<"Enter a plural: "<<endl;
cout<<"Real:" ;
i>>p.real ;
cout<<"Imag:" ;
i>>p.imag ;
cout<<"The plural is " <<p.real <<"+" <<p.imag <<"i\n" ;
}