nextdate问题

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

#include

using namespace std;

int a,b,c,y,m,d;

//判断是否为闰年

bool Feb(int y){

if((2060-y)%4==0)

return 1;

else

return 0;}

//年份的累加

int NextYear(int y){

a=y+1;

if(a>2060)

{cout<<"Next date is out of the record."<<"/n"; return 1;}

else

return a;}

//月份的累加

int NextMonth(int m){

b=m+1;

if(b==13){

b=1;

NextYear(y);}

return b;}

//天数的累加

int NextDay(int d){

c=d+1;

//大月满32天月份加1

if(c==32){

if(m==1|m==3|m==5|m==7|m==8|m==10|m==12) {c=1;

NextMonth(m);}}

//小月满31天月份加1

if(c==31){

if(m==4|m==6|m==9|m==11)

{c=1;

NextMonth(m);}}

//若为闰年,2月满30天,月份加1

if(c==30){

if(Feb(y)&&m==2){

c=1;

b=3;}}

//若不是闰年,2月满29天,月份加1

if(c==29){

if(!Feb(y)&&m==2){

c=1;

b=3;}}

return c;}

//NextDate函数

int NextDate ( int y, int m, int d){

if (y<1900|y>2060|m<1|m>12|d<1|d>31){

cout<<" This date is out of the record , please input the right date."<<"\n"; return 1;}

if(m==4|m==6|m==9|m==11&&d==31) {

cout<<" This date is out of the record , please input the right date."<<"\n"; return 1;}

if(Feb(y)&&m==2&&d>29) {

cout<<" This date is out of the record , please input the right date."<<"\n"; return 1;}

if(!Feb(y)&&m==2&&d>28)

{cout<<" This date is out of the record , please input the right date."<<"\n"; return 1;}

else{

NextDay(d);

cout<<"Next date is"<

return 0;}}

//main函数

int main()

{while(1){

cout << "Please input the current date."<<"\n";

cout << "The domain is from 1900 to 2060"<<"\n";

cout<<"YEAR"<<"\n";

cin >>y;

cout<<"MONTH"<<"\n";

cin>>m;

cout<<"DAY"<<"\n";

cin>>d;

a=y;

b=m;

c=d;

NextDate ( y, m, d);}

return 0;}

相关文档
最新文档