24.3 DATE AND TIME
class Time
{ private : int hr, min, sec; public : Time() {hrs=0;mins=0;secs=0;} Time ( int h, int m, int s); void show(); friend int compare (TIME tx, TIME ty); };
Class time will be needed in many practical applications. Notice the use of friend function compare().
class Date
{ private: int day, month, year; public: Date(); Date(int d , int m , int y); void show(); void validate(Date d) ; } ;
The method validate is really very tricky. The rules of leap years must be taken into account. The readers are advised to collect more information about “Gregorian calendar” before coding.
class Period
{ private : int days, months, years ; public: Period(); ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access