#include<conio.h>
#include<iostream.h>
class sp
{
private:
float a;
float b;
public:
void nhap()
{
cout<<"\nnhap phan thuc: ";
cin>>a;
cout<<"\nnhap phan ao: ";
cin>>b;
}
void hien()
{
if(b>=0) cout<<a<<"+"<<b<<"i";
else cout<<a<<b<<"i";
}
sp operator+(sp x);
sp operator-(sp x);
sp operator*(sp x);
sp operator/(sp x);
};
sp sp::operator+(sp x)
{
sp s;
s.a=this->a+x.a;
s.b=this->b+x.b;
return s;
}
sp sp::operator-(sp x)
{
sp t;
t.a=this->a-x.b;
t.b=this->b-x.b;
return t;
}
sp sp::operator*(sp x)
{
sp u;
u.a=this->a*x.a-this->b*x.b;
u.b=this->a*x.b+this->b*x.a;;
return u;
}
sp sp::operator/(sp x)
{
sp v;
v.a=(this->a*x.a+this->b*x.b)/(x.a*x.a+x.b*x.b);
v.b=(this->b*x.a-this->a*x.b)/(x.a*x.a+x.b*x.b);
return v;
}
int main()
{
sp c,d,s,t,u,v;
cout<<"nhap so phuc thu 1:";
c.nhap();
cout<<"\nso phuc vua nhap la: ";
c.hien();
cout<<"\nnhap so phuc thu 2:";
d.nhap();
cout<<"\nso phuc vua nhap la: ";
d.hien();
s=c+d;
t=c-d;
u=c*d;
v=c/d;
cout<<"\nso phuc tong la: ";
s.hien();
cout<<"\nso phuc hieu la: ";
t.hien();
cout<<"\nso phuc tich la: ";
u.hien();
cout<<"\nso phuc thuong la: ";
v.hien();
return 0;
}