急急急~菜鸟提问,C++高手请进..

来源:百度知道 编辑:UC知道 时间:2024/06/14 08:43:54
编程实现,给出年、月、日,如2007年10月1日,计算出这一天是属于该年的第几天。要求分别编写计算闰年的函数和计算日期的函数。(提示:闰年满足的条件是能被4整除但不能被100整除活着能被400整除。)
谢谢啦

晕,这么简单都不会呀,是02.23.04啊

02年23月4日

//判断闰年
bool Date::leapyear()
{
if(year%400==0 ||year%100!=0&&year%4==0)
return true;
return false;
}

//返回天数
int Date::checkday(int d)
{
static int daypermonth[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
if(d>0 && d<=daypermonth[month])
return d;
if(month==2 && d==29 && leapyear()!=0)
return d;
cout<<"非法的日期输入,初始化为1"<<endl;
return 1;
}

完整源码:
#include<iostream.h>
class Date
{
public:
Date(int =1,int=1,int=1990);
void print();
bool leapyear();
int checkday(int );
void increaseday();
bool endofmonth();
private:
int month;
int day;
int year;

};

Date::Date(int m,int d,int y)
{
month=(m>0&&m<=12)? m:1;
year=(y>=1900 && y<3050)?y:1900;
day=checkday(d);
}
voi