#include #include #include typedef char string80[80];
class date { public: date() {} date(int y, int m, int d) { setdate(y, m, d); } void setdate(int y, int m, int d) { year = y; month = m; day = d; } void getstringdate(string80 &date) { sprintf(date, \"%d/%d/%d\", year, month, day); } protected: int year, month, day; };
class time { public: time() {} time(int h, int m, int s) { settime(h, m, s); } void settime(int h, int m, int s) { hours = h; minutes = m; seconds = s; } void getstringtime(string80 &time) { sprintf(time, \"%d:%d:%d\", hours, minutes, seconds); } protected: int hours, minutes, seconds; };
class timedate:public date, public time { public: timedate():date() {} timedate(int y, int mo, int d, int h, int mi, int s):date(y, mo, d), time(h, mi, s) {} void getstringdt(string80 &dtstr) { sprintf(dtstr, \"%d/%d/%d;%d:%d:%d\", year, month, day, hours, minutes, seconds); } };
void main() { timedate date1, date2(1998, 8, 12, 12, 45, 10); string80 demostr; date1.setdate(1998, 8, 7); date1.settime(10, 30, 45); date1.getstringdt(demostr); cout<<\"the date1 date and time is:\"< date1.getstringdate(demostr); cout<<\"the date1 date is:\"< date1.getstringtime(demostr); cout<<\"the date1 time is:\"< date2.getstringdt(demostr); cout<<\"the date2 date and time is:\"< } |