码迷,mamicode.com
首页 > 其他好文 > 详细

期中测试

时间:2019-04-30 15:41:46      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:sum   turn   date()   div   return   get   date   ==   splay   

1. 补足日期类实现,使得能够根据日期获取这是一年中第多少天。

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

 

期中测试

标签:sum   turn   date()   div   return   get   date   ==   splay   

原文地址:https://www.cnblogs.com/dadadacy/p/10796143.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!