描述
请实现一个分数类,使程序输出正确结果(保证运算过程中不会出现分母为0的情况)
#include <iostream>
using namespace std;
int gcd(int x, int y){
return x%y==0?y:gcd(y,x%y);
}
class Fraction
{
int num, den;
public:
// 在此处补充你的代码
};
int main() {
int a,b,c;
cin >> a >> b >> c;
Fraction f(a, b), g(c);
f *= g;
cout << f << endl;
f /= g;
cout << f << endl;
f = f * f;
cout << f << endl;
f = f / g;
cout << f << endl;
cout << (float) f << endl;
return 0;
}
样例输入
3 5 7
样例输出
21/5
3/5
9/25
9/175
0.0514286