lab.cpp/tp2/ZFraction.cpp

23 lines
574 B
C++

/* [0] CONSTRUCTEUR
=========================================================*/
ZFraction::ZFraction(int a, int b) : a(a), b(b){}
/* [1] Getters
=========================================================*/
void ZFraction::toString() const{ cout << "(" << this->a << "/" << this->b << ")"; }
/* [2] Operateurs
=========================================================*/
/* (1) Addition */
ZFraction& operator+=(ZFraction const& x){
int new_a = this->a * x.b + this->b * x.a;
int new_b = this->b * x.b;
ZFraction out = ZFraction(new_a, new_b);
return &out;
}