定义一个日期类Date,内有数据成员year、month和day,分别代表年、月、日,并若干有成员函数:构造函数用于初始化数据成员,isLeap函数用于闰年的判断。编写主函数:创建日期对象,判断该年是否是闰年。
输入格式:
每组测试数据仅包含一个测试用例,每个测试用例占一行包括三个数,分别表示年、月、日。
输出格式:
如果是闰年则输出yes,不是则输出no。
输入样例:
2006 3 5
输出样例:
no
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
#include <iostream>
using namespace std;
class Date
{
public:
Date()
{
year=0;
month=0;
day=0;
}
void set_Date();
void show_Date();
private:
int year,month,day;
};
void Date::set_Date()
{
cin>>year>>month>>day;
}
void Date::show_Date()
{
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
cout << "yes";
else
cout << "no";
}
int main()
{
Date d1;
d1.set_Date();
d1.show_Date();
return 0;
}