// Time class // Version 1.2 // // New in this version: constructors. #include using std::cout; using std::cin; using std::istream; using std::ostream; class Time { public: // Time() : hours(99), minutes(99) {} // Time(int h) : hours(h), minutes(0) {} // Time(int h, int m) : hours(h), minutes(m) {} Time() : Time(99, 99) {} Time(int h) : Time(h, 0) {} Time(int h, int m) : hours(h), minutes(m) {} // Time() {} // Time(int h) : Time(h, 0) {} // Time(int h, int m) : hours(h), minutes(m) {} void read(istream & in); void print(ostream & out) const; double minus(const Time & t2) const; private: int hours; int minutes; // int hours = 99; // int minutes = 99; }; inline void Time::read(istream & in) { in >> hours; in.get(); // colon in>> minutes; } inline void Time::print(ostream & out) const { out << hours << ':'; if (minutes < 10) out << 0; out << minutes; } inline double Time::minus(const Time & t2) const { return (hours + minutes/60.0) - (t2.hours + t2.minutes/60.0); } void println(const Time & t, ostream & out) { t.print(out); out << '\n'; } int main() { Time t; // t.initialize(); println(t, cout); Time wake_up_time(6,15); println(wake_up_time, cout); Time noon(12); println(noon, cout); // Time six_thirty(6,30); // wake_up_time = six_thirty; wake_up_time = Time(6,30); println(wake_up_time, cout); // wake_up_time = Time(6); wake_up_time = 6; println(wake_up_time, cout); Time midnight = 0; println(midnight, cout); Time a_times[5]; for (const Time & t : a_times) println(t, cout); return 0; }