下面附上我的代码 公元之后的我写了 公元前还没有
#include
using namespace std;
class Date
{
friend int Delta(Date d1, Date d2)
{
int days = 0;
if (d1.year > 0&&d2.year > 0)
{
for (int i = d1.year; i < d2.year; i++)
{
if ((i % 4 == 0 && i % 100 == 0) || i % 400 == 0)
days += 366;
else
days += 365;
}
}
else
{
for (int i = d1.year; i < d2.year; i++)
{
if (((i+1) % 4 == 0 && (i+1) % 100 == 0) || (i+1) % 400 == 0)
days += 366;
else
days += 365;
}
}
if (d1.month > 0)
{
for (int j = 1; j < d1.month; j++)
{
if (j == 1 || j == 3 || j == 5 || j == 7 || j == 8 || j == 10 || j == 12)
days -= 31;
else if (j == 4 || j == 6 || j == 9 || j == 11)
days -= 30;
else if (j == 2)
{
if ((d1.year % 4 == 0 && d1.year % 10 == 0) || d1.year % 400 == 0)
days -= 29;
else
days -= 28;
}
}
}
else
{
}
days -= d1.day;
if (d2.month > 0)
{
for (int k = 1; k < d2.month; k++)
{
if (k == 1 || k == 3 || k == 5 || k == 7 || k == 8 || k == 10 || k == 12)
days += 31;
else if (k == 4 || k == 6 || k == 9 || k == 11)
days += 30;
else if (k == 2)
{
if ((d2.year % 4 == 0 && d2.year % 10 == 0) || d2.year % 400 == 0)
days += 29;
else
days += 28;
}
}
}
else
{
}
days += d2.day;
return days;
}
friend std::istream & operator>>(std::istream & is, const Date &d)
{
is >> d.year;
cout > d.month;
cout > d.day;
cout > date1 >> date2;
int delt = Delta(date2, date1);
cout |