7.8.cpp

来自「这是C++的一部分练习程序!对初学者有一定的帮助作用。」· C++ 代码 · 共 51 行

CPP
51
字号
#include <iostream.h>
struct date
{
	int year,month,day;
};
void main()
{
	struct date today,tomorrow;
	int is_leap_year(struct date &),number_of_days(struct date &);
	cout<<"Enter today's date(yyyy mm dd): ";
	cin>>today.year>>today.month>>today.day;
	if(today.day!=number_of_days(today))
	{
		tomorrow.day=today.day+1;
		tomorrow.month=today.month;
		tomorrow.year=today.year;
	}
	else if(today.month==12)
	{
		tomorrow.day=1;
		tomorrow.month=1;
		tomorrow.year=today.year+1;
	}
	else
	{
		tomorrow.day=1;
		tomorrow.month=today.month+1;
		tomorrow.year=today.year;
	}
	cout<<"Tomorrow's date is "<<tomorrow.year<<'/'<<tomorrow.month<<'/'<<tomorrow.day<<endl;
}
int is_leap_year(struct date &rd)
{
	int leap_year=0;
	if((rd.year%4==0&&rd.year%100!=0)||rd.year%400==0)
		leap_year=1;
	return leap_year;
}
int number_of_days(struct date &rd)
{
	int day;
	int days_month[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
	if(is_leap_year(rd)&&(rd.month==2))
		day=29;
	else
		day=days_month[rd.month];
	return day;
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?