[CODE]Rational operator+ (const Rational &r1,const Rational &r2){
return r1.Add(r2);
}
Rational operator- (const Rational &r1,const Rational &r2){
return r1.Subtract(r2);
}
Rational operator* (const Rational &r1,const Rational &r2){
return r1.Multiply(r2);
}
Rational operator/ (const Rational &r1,const Rational &r2){
return r1.Divide(r2);
}
//stream operators
ostream& operator<< (ostream &sout,const Rational &r){
r.Insert(sout);
return sout;
}
istream& operator>> (istream &sin ,Rational &r){
r.Extract(sin);
return sin;
}
//bool operator
bool operator== (const Rational &r1,const Rational &r2){
return r1.Equal(r2);
}
bool operator< (const Rational &r1,const Rational &r2){
return r1.LessThan(r2);
}
bool operator<= (const Rational &r1,const Rational &r2){
if (r1.LessThan(r2) || r1.Equal(r2))
return true;
else
return false;
}
bool operator> (const Rational &r1,const Rational &r2){
if (!r1.LessThan(r2))
return true;
else
return false;
}
bool operator>= (const Rational &r1,const Rational &r2){
if (!r1.LessThan(r2) || r1.Equal(r2))
return true;
else
return false;
}[/CODE]
这是分数的一些重载,你看看吧,道理一样的!