急.急.急.希望是自己写的程序, 因为急用,所以希望月快越好!!!如果写得好,再加高分!!
来源:百度知道 编辑:UC知道 时间:2024/05/13 05:42:32
1.求解有理数分式方程这个 希望能用以上创建的Rational类求解有理数分式方程 a/bx+c/d=e/f
#include<iostream>
using namespace std;
//numerator 分子
//denominator分母
//求最大公约数函数,用于约分
int gcd(int m,int n)
{
if(n==0)return m;
return gcd(n,m%n);
}
class Rational
{
private:
int numer;
int denom;
public:
Rational(int n=0,int d=1)//带默认参数的构造函数,整数与分数的运算迎刃而解
{
numer=n;
denom=d;
}
void rev(Rational &a){numer=a.denom;denom=a.numer;}//倒数
friend ostream& operator<<(std::ostream&, const Rational&);
friend istream& operator>>(std::istream&, Rational&);
friend bool operator==(const Rational&, const Rational&);
friend bool operator<(const Rational&, const Rational&);
friend bool operator>(const Rational&, const Rational&);
friend bool operator>=(const Rational&, const Rational&);
friend bool operator<=(const Rational&, const Rational&);
friend Rational operator +(const Rational&,const Rational&);