展开全部
#include "stdio.h"
class Date
{
private:
int year,month,day;
public:
Date(){year=0;month=0;day=0;}//默认构造函数
Date(int x,int y,int z){year=x;month=y;day=z;}//重载构造函数
void add(int m);//加天数
void del(int m);//减天数
int diff(Date& q);//日期差
void display();//显示
};
void Date::add(int m)
{
int d[12]={31,28,31,30,31,30,31,31,30,31,30,31},temp,f;//d为12个月每个月天数的数组
f=0;
while (m>0)
{
if (year%100==0)
d[1] = (year%400==0?29:28);//如果是闰年,2月天数为32313133353236313431303231363533e58685e5aeb93133333261646129
else
d[1] = (year%4==0?29:28);//如果是闰年,2月天数为29
temp=d[month-1]-day;
if (temp>=m)//如果所加天数未超过当月剩余天数
{