cpp2.cpp
来自「学习VC++的最基础程序」· C++ 代码 · 共 83 行
CPP
83 行
#include<iostream>
using namespace std;
int x=0;
class Date{
int y;
int m;
int d;
public:
void print(){cout<<d<<"日"<<m<<"月"<<y<<"年"<<endl;}
void secondDay();
void shezhi();
};
void Date::secondDay()
{
if(m==2){
if((y%4==0&&y%100!=0)||y%400==0){
if(d==29){d=1;m=3;}
else if(d<29)d+=1;
else cout<<"error"<<endl;
}
else
if(d==28){d=1;m=3;}
else if(d<28)
d+=1;
else cout<<"error"<<endl;
}
else
if(m<8&&m>=1){
if(d==30+m%2){d=1;m+=1;}
else if(d<30+m%2)
d+=1;
else cout<<"error"<<endl;
}
else
if(m>7&&m<=12){
if(d==31-m%2){d=1;m+=1;}
else if(d<31-m%2)
d+=1;
else cout<<"error"<<endl;
}
else cout<<"error"<<endl;
}
void Date::shezhi()
{
cout<<"请输入当前日期(日,月,年)"<<endl;
cin>>d>>m>>y;
if(m==2){
if((y%4==0&&y%100!=0)||y%400==0){
if(d>29||d<1)
{cout<<"error"<<endl;goto end;}
}
else
if(d>28||d<1)
{cout<<"error"<<endl;goto end;}
}
else
if(m<8&&m>=1){
if(d>30+m%2||d<1)
{cout<<"error"<<endl;goto end;}
}
else
if(m>7&&m<=12){
if(d>31-m%2||d<1)
{cout<<"error"<<endl;goto end;}
}
else
{cout<<"error"<<endl;goto end;}
x+=1;
end:
x+=0;
}
int main()
{
Date today;
today.shezhi();
if(x==1){
today.print();
today.secondDay();
today.print();}
else ;
return 1;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?