// Constructors #include using namespace std; class Time { public: // Time() { hours = minutes = 99; } // 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() {} void read(istream& in = cin) { in >> hours; in.get(); // colon in >> minutes; } void print(ostream& out = cout) const { out << hours << ':'; if (minutes < 10) { out << 0; } out << minutes; } bool less_than(const Time& t) const { return (hours < t.hours) || (hours == t.hours && minutes < t.minutes); } private: int hours; int minutes; // int hours = 99; // int minutes = 99; }; void println(const Time& t, ostream& out = cout) { t.print(out); out << endl; } // Test driver for Time int main() { Time t; println(t); // Time wake_up_time(6, 30); // Time wake_up_time(6, 0); // Time wake_up_time(6); Time wake_up_time = 6; println(wake_up_time); // if (wake_up_time.less_than(Time(6,30))) // if (wake_up_time.less_than({6,30})) // if (wake_up_time.less_than({6})) if (wake_up_time.less_than(6)) { cout << "yes\n"; } else { cout << "no\n"; } println(Time(8, 35)); println({8, 35}); // bad idea println(8); // bad idea Time(12, 45).print(); // {12, 45}.print(); // does not compile cout << endl; Time a[5]; for (const Time& t : a) { println(t); } return 0; }