题目:
小陆每天要写一份工作日报,日报标准是“入职第X天-小陆-XXX”,对于“入职第几天”,小陆现在每次需要对上次写的日报标题里的天数+1, 遇到周末还要多加2天等等。请你写一段程序,帮小陆自动完成这件事,提供写日期当天的年月日,算出已入职的天数(假定小陆的入职时间是 2014年8月18日)。要求:不能使用时间,日期相关的库函数。
分析:
先将时间封装成类,对于内部的操作采用private方法或者重载运算符的方式封装。计算时间差的时候,先计算年的天数;再加上该年的天数;再减去初始年的天数。
算法代码:
class Time
{
private:
int _Year;
int _Month;
int _Day;
const int LEAPYEARDAYS = 366;
const int NONLEAPYEARDAYS = 365;
bool isLeapYear(int year) const;
int daysOfMonth(int month, int year) const;
public:
Time() {}
Time(int y, int m, int d) : _Year(y), _Month(m), _Day(d) {}
~Time() {}
int operator-(const Time &