1 #include "date.h" 2 #include "utils.h" 3 #include <iostream> 4 using std::cout; 5 using std::endl; 6 Date::Date() 7 { 8 year=1970; 9 month=1; 10 day=1; 11 } 12 Date::Date(int y,int m,int d) 13 { 14 year=y; 15 month=m; 16 day=d; 17 } 18 int Date::getYear() const 19 { 20 return year; 21 } 22 int Date::getMonth() const 23 { 24 return month; 25 } 26 int Date::getDay() const 27 { 28 return day; 29 } 30 int Date::dayOfYear() 31 { 32 int a[12]={31,28,31,30,31,30,31,31,30,31,30,31}; 33 if( (year % 4 == 0 && year % 100 !=0) || (year % 400 == 0) ) 34 { 35 a[1]=29; 36 } 37 int i,sum=0; 38 for(i=0;i<month-1;i++) 39 { 40 sum=sum+a[i]; 41 } 42 sum=sum+day; 43 return sum; 44 45 } 46 void Date::display() 47 { 48 cout<<year<<"年"<<month<<"月"<<day<<"日"<<endl; 49 }