Department of Computer Science | Institute of Theoretical Computer Science | CADMO

Theory of Combinatorial Algorithms

Prof. Emo Welzl and Prof. Bernd Gärtner

#include class Clock { Clock(unsigned int h, unsigned int m, unsigned int s); void tick(); void time(unsigned int h, unsigned int m, unsigned int s); private: unsigned int h_; unsigned int m_; unsigned int s_; }; Clock::Clock(unsigned int& h, unsigned int& m, unsigned int& s) : h_(h), m_(m), s_(s) {} void Clock::tick() { h_ += (m_ += (s_ += 1) / 60) / 60; h_ %= 24; m_ %= 60; s_ %= 60; } void Clock::time(unsigned int& h, unsigned int& m, unsigned int& s) { h = h_; m = m_; s = s_; } int main() { Clock c1 (23, 59, 58); tick(); unsigned int h; unsigned int m; unsigned int s; time(h, m, s); std::cout << h << ":" << m << ":" << s << "\n"; return 0; }