2016-03-05 22:37:08 +00:00
|
|
|
/* [0] CONSTRUCTEUR
|
|
|
|
=========================================================*/
|
2016-03-06 16:29:02 +00:00
|
|
|
ZFraction::ZFraction(int a, int b) : _a(a), _b(b){}
|
2016-03-05 22:37:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [1] Getters
|
|
|
|
=========================================================*/
|
2016-03-06 16:29:02 +00:00
|
|
|
ostream& operator<<(ostream& o, const ZFraction& f){
|
|
|
|
o << "(" << f._a << "/" << f._b << ")";
|
|
|
|
|
|
|
|
return o;
|
|
|
|
}
|
2016-03-05 22:37:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* [2] Operateurs
|
|
|
|
=========================================================*/
|
|
|
|
/* (1) Addition */
|
2016-03-06 16:29:02 +00:00
|
|
|
ZFraction ZFraction::operator+(const ZFraction& x) const{
|
|
|
|
int new_a = _a * x._b + _b * x._a;
|
|
|
|
int new_b = _b * x._b;
|
|
|
|
|
|
|
|
return ZFraction(new_a, new_b);
|
|
|
|
}
|
|
|
|
|
|
|
|
ZFraction& ZFraction::operator+=(const ZFraction& x){
|
|
|
|
*this = *this + x;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* (2) Multiplication */
|
|
|
|
ZFraction ZFraction::operator*(const ZFraction& x) const{
|
|
|
|
int new_a = _a * x._a;
|
|
|
|
int new_b = _b * x._b;
|
2016-03-05 22:37:08 +00:00
|
|
|
|
2016-03-06 16:29:02 +00:00
|
|
|
return ZFraction(new_a, new_b);
|
|
|
|
}
|
2016-03-05 22:37:08 +00:00
|
|
|
|
2016-03-06 16:29:02 +00:00
|
|
|
ZFraction& ZFraction::operator*=(const ZFraction& x){
|
|
|
|
*this = *this * x;
|
|
|
|
return *this;
|
2016-03-05 22:37:08 +00:00
|
|
|
}
|