#include<conio.h>
#include<iostream.h>
#include<math.h>
class ps
{
private:
int a;
int b;
public:
void nhap()
{
cout<<"\nnhap tu so: ";
cin>>a;
do
{
cout<<"nhap mau so: ";
cin>>b;
}
while(b==0);
}
void hien()
{
if(b==0) cout<<"phan so khong ton tai";
else if(b==1) cout<<a<<"/"<<b<<"="<<a;
else if(a==0) cout<<a<<"/"<<b<<"="<<0;
else
{
cout<<a<<"/"<<b;
for(int i=abs(a);i>=2;i--)
if(a%i==0&&b%i==0)
{
cout<<"="<<a/i<<"/"<<b/i;
break;
}
}
}
ps operator+(ps x);
ps operator-(ps x);
ps operator*(ps x);
ps operator/(ps x);
};
ps ps::operator+(ps x)
{
ps s;
s.a=(this->a*x.b)+(x.a*this->b);
s.b=this->b*x.b;
return s;
}
ps ps::operator-(ps x)
{
ps t;
t.a=(this->a*x.b)-(x.a*this->b);
t.b=this->b*x.b;
return t;
}
ps ps::operator*(ps x)
{
ps u;
u.a=this->a*x.a;
u.b=this->b*x.b;
return u;
}
ps ps::operator/(ps x)
{
ps v;
v.a=this->a*x.b;
v.b=this->b*x.a;
return v;
}
int main()
{
ps c,d,s,t,u,v;
cout<<"nhap phan so thu 1:";
c.nhap();
cout<<"\nphan so vua nhap la: ";
c.hien();
cout<<"\nnhap phan so thu 2:";
d.nhap();
cout<<"\nphan so vua nhap la: ";
d.hien();
s=c+d;
t=c-d;
u=c*d;
v=c/d;
cout<<"\nphan so tong la: ";
s.hien();
cout<<"\nphan so hieu la: ";
t.hien();
cout<<"\nphan so tich la: ";
u.hien();
cout<<"\nphan so thuong la: ";
v.hien();
return 0;
}