/* [x] Constructeur =========================================================*/ void Duree::fix(){ int stack(0); // Gestion du debordement de secondes stack = _s; if( stack >= 60 ){ _s = stack % 60; _m += stack / 60; } // Gestion du debordement de minutes stack = _m; if( stack >= 60 ){ _m = stack % 60; _h += stack / 60; } } Duree::Duree(int h, int m, int s) : _h(h), _m(m), _s(s){ this->fix(); } Duree::Duree(const Duree& d) : _h(d._h), _m(d._m), _s(d._s){ this->fix(); } /* [0] Affichage =========================================================*/ ostream& operator<<(ostream& o, const Duree& d){ o << "[" << d._h << ":" << d._m << "," << d._s << "]"; return o; } /* [1] Egalite =========================================================*/ bool Duree::operator==(const Duree& x){ return _h == x._h && _m == x._m && _s == x._s; } /* [2] Addition =========================================================*/ void Duree::operator+=(const Duree& d){ _h += d._h; _m += d._m; _s += d._s; this->fix(); } Duree operator+(Duree& l, Duree& r){ Duree tmp(l); tmp += r; return tmp; } /* [3] Multiplication =========================================================*/ void Duree::operator*=(const int d){ _h *= d; _m *= d; _s *= d; this->fix(); } Duree operator*(int l, Duree& r){ Duree tmp(r); tmp *= l; return tmp; } Duree operator*(Duree& l, int r){ Duree tmp(l); tmp *= r; return tmp; }