期中考试

 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 }

 

转载于:https://www.cnblogs.com/0122Frank/p/10795955.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值