当前位置:文档之家› nextdate问题

nextdate问题

#include <iostream>
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"<<a<<"."<<b<<"."<<c<<"\n"<<"\n";
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;}。

相关主题