输入一个年份,判断它是否是闰年

版权声明:所有博客均由作者本人原创,若要转载,请注明出处。谢谢 https://blog.csdn.net/LU_Leo/article/details/82492689

闰年定义:能被400整除的是闰年或者能被4整除但不能被100整除

如:2000是闰年,2100不是闰年

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
using namespace std;
class mydate
{
private:
	int m_year;
	int m_month;
	int m_day;
public:
	void print_date()
	{
		cout << m_year << "年" << m_month << "月" << m_day << "日" << endl;
	}
	mydate(int y, int m, int d)
	{
		m_year = y;
		m_month = m;
		m_day = d;
	}
	void is_leap_year()
	{
		if (m_year % 400 == 0 || (m_year % 4 == 0 && m_year % 100 != 0))
			cout << m_year << "是闰年" << endl;
		else
			cout << m_year << "不是闰年" << endl;
		cout << endl;

	}
};
int main()
{
	mydate date(2000, 3, 4);
	date.print_date();
	date.is_leap_year();
	mydate date2(1996, 2, 3);
	date2.print_date();
	date2.is_leap_year();
	mydate date3(2100, 3, 5);
	date3.print_date();
	date3.is_leap_year();
	return 0;
}

猜你喜欢

转载自blog.csdn.net/LU_Leo/article/details/82492689
今日推荐