#include <iostream.h>
class Date
{
private:
int year,month,day;
public:
Date(){}
Date(int y,int m,int d);
void display()
{
cout<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
}
int isLeapyear(int y);
void nextday();
};
void Date::nextday()
{
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if((month==12)&&(day==31))
{
cout<<"当前日期为"<<day<<"年"<<month<<"月"<<day<<"日"<<endl;
cout<<endl;
cout<<"明天日期为:"<<year+1<<"年"<<1<<"月"<<1<<"日"<<endl;
cout<<endl;
}
else if(day==31)
{
cout<<"当前日期为"<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
cout<<endl;
cout<<"明天日期为:"<<year<<"年"<<month+1<<"月"<<1<<"日"<<endl;
cout<<endl;
}
else
{
cout<<"当前日期为"<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
cout<<endl;
cout<<"明天日期为:"<<year<<"年"<<month<<"月"<<day+1<<"日"<<endl;
cout<<endl;
}
break;
case 2:
if(isLeapyear(year))
{
if((month==12)&&(day==29))
{
cout<<"当前日期为"<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
cout<<endl;
cout<<"明天日期为:"<<year+1<<"年"<<1<<"月"<<1<<"日"<<endl;
cout<<endl;
}
else if(day==29)
{
cout<<"当前日期为"<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
cout<<endl;
cout<<"明天日期为:"<<year<<"年"<<month<<"月"<<1<<"日"<<endl;
cout<<endl;
}
else
{
cout<<"当前日期为"<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
cout<<endl;
cout<<"明天日期为:"<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
cout<<endl;
}
}
else
{
if((month==12)&&(day==28))
{
cout<<"当前日期为"<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
cout<<endl;
cout<<"明天日期为:"<<year+1<<"年"<<1<<"月"<<1<<"日"<<endl;
cout<<endl;
}
else if(day==28)
{
cout<<"当前日期为"<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
cout<<endl;
cout<<"明天日期为:"<<year<<"年"<<month+1<<"月"<<1<<"日"<<endl;
cout<<endl;
}
else
{
cout<<"当前日期为"<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
cout<<endl;
cout<<"明天日期为:"<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
cout<<endl;
}
}
break;
case4:
case6:
case9:
case11:
if((month==12)&&(day==30))
{
cout<<"当前日期为"<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
cout<<endl;
cout<<"明天日期为:"<<year+1<<"年"<<1<<"月"<<1<<"日"<<endl;
cout<<endl;
}
else if(day==30)
{
cout<<"当前日期为"<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
cout<<endl;
cout<<"明天日期为:"<<year<<"年"<<month+1<<"月"<<1<<"日"<<endl;
cout<<endl;
}
else
{
cout<<"当前日期为"<<year<<"年"<<month<<"月"<<day<<"日"<<endl;
cout<<endl;
cout<<"明天日期为:"<<year<<"年"<<month<<"月"<<day+1<<"日"<<endl;
cout<<endl;
}
break;
}
}
int Date::isLeapyear(int y)
{
if(((y%4==0)&&(y%100!=100))||(y%400==0)) return 1;
else return 0;
}
Date::Date(int y,int m,int d)
{
if((y>=1900)&&(y<=2050))
{
year=y;
if((m>=1)&&(m<=12))
{
month=m;
switch(month)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if((d>=1)&&(d<=31))
{
day=d;
}
else
{
cout<<"day不合理"<<endl;
}
break;
case 4:
case 6:
case 9:
case 11:
if((d>=1)&&(d<=30))
{
day=d;
}
else
{
cout<<"day不合理"<<endl;
}
break;
case 2:
if(isLeapyear(year))
{
if((d>=1)&&(d<=29))
{
day=d;
}
else
{
cout<<"day不合理"<<endl;
}
}
else
{
if((d>=1)&&(d<=28))
{
day=d;
}
else
{
cout<<"day不合理"<<endl;
}
}
}
}
else
{
cout<<"month不合理"<<endl;
}
}
else
{
cout<<"year不合理"<<endl;
}
}
void main()
{
Date d1(2010,2,28);
d1.nextday();
}