一个C++分数计算器的程序,通分函数有错误,求指点,怎么改?
问题描述:
这是两个函数,上面约分函数应该是正确的,
求怎样调用约分函数写通分函数
void Grade::Reduction()//约分
{
int a, b, CommonDivisor, Remainder;//公约数,余数
a = abs(numerator);//分子取绝对值
b = abs(denominator);//分母取绝对值
{
if (a > b)
{
Remainder = a % b;
while (Remainder != 0)
{
int t;
t = Remainder;
a = b;
b = t;
Remainder = a % b;
}
CommonDivisor = b;
}
if (a == b)
{
CommonDivisor = a;
}
if (a < b)
{
Remainder = b % a;
while (Remainder != 0)
{
int t;
t = Remainder;
b = a;
a = t;
Remainder = b % a;
}
CommonDivisor = a;
}
}//最大公约
numerator /= CommonDivisor;//约分后分子
denominator /= CommonDivisor;//约分后分母
}
void Grade::ToCommond(Grade &grade) //通分
{
int temp;
Reduction();
grade.Reduction();
numerator *= grade.denominator;
grade.numerator *= denominator;
//////////后面不会写了