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(); ...

Get Object Oriented Programming with C++, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.