#include"Khai Báo.h"
void NhapPhanSo(SPhanSo *a)
{
printf("Nhap Tu So:");
cin>>a->TuSo;
do
{
printf("Nhap Mau So:");
cin>>a->MauSo;
if(a->MauSo==0)
{
cout<<" Mau So Phai Khac Khong Moi Ban Nhap Lai Tu So!";
}
}
while(a->MauSo==0);
}
void XuatPhanSo(SPhanSo *a)
{
cout<<a->TuSo<<"/"<<a->MauSo;
}
int UCLN(int a,int b)
{
a=abs(a);
b=abs(b);
while (a!=b)
{
if(a>b)
{
a-=b;
}
else
if(a<b)
{
b-=a;
}
}
return a;
}
void RutGon(SPhanSo *a)
{
int ucln=UCLN(a->TuSo,a->MauSo);
a->TuSo/=ucln;
a->MauSo/=ucln;
}
SPhanSo TinhTong(SPhanSo a,SPhanSo b)
{
SPhanSo Tong;
Tong.TuSo=a.TuSo*b.MauSo+a.MauSo*b.TuSo;
Tong.MauSo=a.MauSo*b.MauSo;
//RutGon(&Tong);
return Tong;
}
SPhanSo operator +(SPhanSo a,SPhanSo b)
{
return TinhTong(a,b);
}
bool kt(SPhanSo a)
{
return UCLN(a.TuSo,a.MauSo)==1?true:false;
}
SPhanSo QuyDong(SPhanSo a,SPhanSo b)
{
SPhanSo phanso1;
if(a.MauSo!=b.MauSo)
{
phanso1.TuSo=a.TuSo;
phanso1.MauSo=a.MauSo*b.MauSo;
}
RutGon(&phanso1);
return phanso1;
}
bool KTTinhChatPhanSo(SPhanSo a)
{
if(a.TuSo<0&&a.MauSo<0||a.TuSo>0&&a.MauSo>0)
{
return true;
}
else
return false;
}
bool operator <(SPhanSo a,int x)
{
return ((float)a.TuSo/a.MauSo)<x;
}
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.