文章
84
粉丝
408
获赞
33
访问
867.6k
#include<iostream>
using namespace std;
int days[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
class Date{
private:
int year;
int month;
int day;
public:
Date(){}
Date(int y, int m, int d):year(y),month(m),day(d){}
~Date(){}
bool fun();//判断是否闰二月
bool Setvalue(int y, int m, int d);
int calday();
};
bool Date::fun()
{
if (year%400 == 0)
return true;
else if (year%100 != 0 && year%4 == 0)
return true;
else
return false;
}
bool Date::Setvalue(int y, int m, int d)
{
year = y;
month = m;
day = d;
if (month <= 0 || month > 12)
return false;
else if (day <= 0)
return false;
else if (!fun() && day > days[month-1])
return false;
else if (month == 2 && fun() && day > days[month-1] + 1)
return false;
else
return true;
}
int Date::calday()
{
int sum = 0;
for (int i = 1; i < month; i++) {
sum += days[i-1];
}
sum += day;
if (fun() && ...
登录后发布评论
暂无评论,来抢沙发