bai2-week4
// sp phu'c
#include<iostream.h>
#include<math.h>
#include<conio.h>
class SP
{
int pt,pa;
public:
void nhap();
void in();
SP operator*(SP);
void chia(SP);
SP operator+(SP);
SP operator-(SP);
friend float tinh(SP);
};
void SP::nhap()
{
cout<<"nhap phan thuc: ";cin>>pt;
cout<<"nhap phan ao: ";cin>>pa;
}
void SP::in()
{
cout<<pt<<"+"<<pa<<"i
";
}
SP SP::operator*(SP a)
{ SP kq;
kq.pt=pt*a.pt;
kq.pa=pa*a.pa;
return(kq);
}
SP SP::operator+(SP a)
{ SP kq;
kq.pt=pt+a.pt;
kq.pa=pa+a.pa;
return(kq);
}
SP SP::operator-(SP a)
{ SP kq;
kq.pt=pt-a.pt;
kq.pa=pa-a.pa;
return(kq);
}
void SP::chia(SP a)
{ float x,y;
cout<<(x=float(pt)/float(a.pt))<<"+"<<(y=float(pa)/float(a.pa))<<"i
";
}
float tinh(SP a)
{ return(sqrt(a.pt*a.pt+a.pa*a.pa)); }
void main()
{
SP a,b,k,h,i;
a.nhap() ; cout<<'
'; b.nhap();
k=a+b;k.in();
h=a-b;h.in();
i=a*b;i.in();
a.chia(b);
cout<<tinh(a)<<'
'<<tinh(b);// hoac co the sd qua ham ban
getch();
}
Bạn đang đọc truyện trên: AzTruyen.Top