1

 1 #include "date.h"
 2 #include "utils.h" 
 3 #include <iostream>
 4 using std::cout;
 5 using std::endl;
 6 
 7 Date::Date():year(1970),month(1),day(1){}
 8 Date::Date(int y,int m,int d):year(y),month(m),day(d){}
 9 void Date::display(){
10     cout<<year<<"-"<<month<<"-"<<day<<endl;
11 }
12 int Date::getYear() const{return year;}
13 int Date::getMonth() const{return month;}
14 int Date::getDay() const{return day;}
15 int Date::dayOfYear(){
16     int k=0,s=0;
17     if(isLeap(year)==true) k=1;
18     for(int i=1;i<month;i++){
19         if(i==2) s+=(28+k);
20         else if(i%2==1&&i<=7) s+=31;
21         else if(i%2==0&&i<=7) s+=30;
22         else if(i%2==1&&i>7) s+=30;
23         else s+=31;
24     }
25     s+=day;
26     return s;
27 }
28 // 补足程序,实现Date类中定义的成员函数

 

第二题,没写完:

 1 #ifndef ARTICLE_H
 2 #define ARTICLE_H
 3 #include<string>
 4 using namespace std;
 5 class Article{
 6 public:
 7     Article(string a,string b,string c);
 8     void hbt(string a,string b);
 9     void hnr(string a,string b);
10     void print();
11 private:
12     string title,content,publicTime,lastUpdateTime;
13 }
14 #endif
 1 #include<iostream>
 2 #include<string>
 3 #include"article.h"
 4 ;using namespace std;
 5 /*
 6 class Article{
 7 public:
 8     Article(string a,string b,string c);
 9     void hbt(string a,string b);
10     void hnr(string a,string b);
11     void print();
12 private:
13     string title,content,publicTime,lastUpdateTime;
14 }
15 */
16 Article::Article(string a,string b,string c):title(a),content(b),publicTime(c),lastUpdateTime(c){}
17 void Article::hbt(string a,string b){title=a;lastUpdateTime=b;}
18 void Article::hnr(string a,string b){content=a;lastUpdateTime=b;}
19 void Article::print(){
20     cout<<"title"<<title<<"\n"
21         <<"content"<<content<<"\n"
22         <<"publicTime"<<publicTime<<"\n"
23         <<"lastUpdateTime"<<lastUpdateTime<<"\n"<<endl;
24 }

 

posted @ 2019-04-30 15:13  淳简拉基茨德  阅读(436)  评论(0)    收藏  举报