#include <iostream>
#include <iomanip>
using namespace std;
class Rational
{
private:
signed int x;
signed int y;
public:
Rational()
{
x = 0;
y = 1;
}
void Add(int a, int b,int c,int d)
{
x = (a * d) + (c * b);
y = b * d;
}
void Sub(int a, int b, int c, int d)
{
x = (a * d) - (c * b);
y = b * d;
}
void Mul(int a, int b, int c, int d)
{
x = a * c;
y = b * d;
}
void Div(int a, int b, int c, int d)
{
x = a * d;
y = b * c;
}
void PrintFloat()
{
float m, n;
m = (float)x;
n = (float)y;
cout << setprecision(6) << m / n << endl;
}
void Print()
{
cout << x << "/" << y << endl;
}
};
int main()
{
int a, b, c, d;
cin >> a >> b >> c >> d;
Rational my;
my.Add(a, b, c, d);
my.Print();
my.Sub(a, b, c, d);
my.PrintFloat();
my.Mul(a, b, c, d);
my.Print();
my.Div(a,b,c,d);
my.PrintFloat();
}
【无标题】
最新推荐文章于 2024-10-12 22:47:18 发布