其中考试

 1 Date::Date():year(1971),month(1),day(1){} // 默认构造函数,将日期初始化为1970年1月1日 
 2 Date::Date(int y, int m, int d):year(y),month(m),day(d){}// 带有形参的构造函数,用形参y,m,d初始化年、月、日 
 3 void Date::display(){
 4     cout<<year<<"-"<<month<<"-"<<day<<endl;
 5 } // 显示日期 
 6 int Date::getYear() const{
 7     return year;
 8 }  // 返回日期中的年份 
 9 int Date::getMonth() const {
10     return month;
11 }// 返回日期中的月份 
12 int Date::getDay() const{
13     return day;
14 } // 返回日期中的日字 
15 int Date::dayOfYear(){
16     int a[12]={31,28,31,30,31,30,31,31,30,31,30,31},b=0,i;
17     if(year%4==0&&year%100!=0||year%400==0)
18         a[2]=29;
19     for(i=0;i<month-1;i++)
20     {
21         b+=a[i];
22     }
23     b+=day;
24     return b;

posted on 2019-04-30 15:14  吵闹机器人  阅读(139)  评论(0编辑  收藏  举报