完美版nextday程序。可以根据平年闰年智能算出明天日期
来源:互联网 发布:台湾网络电视机顶盒 编辑:程序博客网 时间:2024/04/29 05:51
#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();
}
- 完美版nextday程序。可以根据平年闰年智能算出明天日期
- 根据日期获取当月天数(无需判断平年闰年)
- 利用友元 算出nextday。
- 平年闰年算法
- java判断闰年、平年
- 判断闰年平年
- 计算闰年平年
- C#判断闰年平年
- 平年闰年示意图
- 闰年平年问题
- 判读平年还是闰年
- 平年,闰年,回文数
- 判断平年闰年
- 平年闰年的研究
- 判断平年闰年
- 判断平年还是闰年
- 根据日期算出星期几
- 如何根据日期字符串算出星座?
- spring security 获取当前用户信息
- AT070TN83 V1.0 背光不亮
- Portlet学习分析笔记
- 清华校长送给毕业生的五句话(转)
- 分布式事务 日志
- 完美版nextday程序。可以根据平年闰年智能算出明天日期
- web.xml详细配置!
- sleep()和wait()的区别
- 终于成功地在Pluto中部署了一个Portlet了
- discuz 对密码的加密
- [Linux入门系列].1.3.VMWare中安装Windows XP
- android.view.WindowLeaked异常解决方法
- 关于MYSQL Error:ERROR 1005 (HY000) at line 3: Can't create table '.\xx.frm'错误
- Word 2007 无法创建工作文件终级解决方案