#include <iostream>
#include <string>
#include <math.h>
using namespace std;
class CDate
{
friend ostream &operator<<(ostream &os, const CDate &other);
public:
CDate(int y = 0, int m = 0, int d = 0)
{
m_year = y;
m_month = m;
m_day = d;
}
bool IsLeapYear(int year); //判断是否是闰年
int DateToOn(const CDate &other); //日期转换为从0年0月0日起的天数
int MonthDay(int year, int month); //当前月份有几天
CDate operator +(const CDate &other); //两个日期相加
int operator -(const CDate &other); //两个日期相减的天数
CDate operator +(int nday); //当前日期加上nday天
CDate operator -(int nday); //当前日期减去nday天
private:
int m_year;
int m_month;
int m_day;
};
bool CDate::IsLeapYear(int year)
{
return ((year % 400 == 0) || (year % 4 == 0 && year % 100 != 0));
}
int CDate::DateToOn(const CDate &other)
{
int sumday = 0;
sumday = other.m_year * 365;
for(int i = 1; i < other.m_year; ++i)
{
if(IsLeapYear(i))
{
sumday++;
}
}
int sum_day;
switch(other.m_month) //计算本月一起共有多少天
{
case 1:
sum_day = 0;
break;
case 2:
sum_day = 31;
break;
case 3:
sum_day = 59;
break;
case 4:
sum_day = 90;
case 5:
sum