式武神

导航

期中

1.

#ifndef DATE_H
#define DATE_H
#include<iostream>
using namespace std;
class Date {
public:
Date();
Date(int y, int m, int d):year(y),month(m),day(d){}  
int getYear() const{cout<<year;
return 0;
} 
int dayOfYear(); 
private:
int year;
int month;
int day;
};
int Date::dayOfYear(){
    int n;
    if(year%4==0&&year%100!=0)
n=29;
    else
        n=28;
    if(month==1)
        n=day;
    else if(month==2)
        n=day+31;
    else if(month==3)
        n=n+day+31;
    else if(month==4)
        n=n+day+62;
    else if(month==5)
        n=n+day+92;
    else if(month==6)
        n=n+day+123;
    else if(month==7)
        n=n+day+153;
    else if(month==8)
        n=n+day+184;
    else if(month==9)
        n=n+day+215;
    else if(month==10)
        n=n+day+245;
    else if(month==11)
        n=n+day+276;
    else if(month==12)
        n=n+day+306;
    cout<<n;
    return 0;
}

#endif
date.h
#include<iostream>
#include"date.h"
using namespace std;
int main()
{
    int y,m,d;
    while(cin>>y>>m>>d)
    {
        Date a(y,m,d);
            cout<<"";
            a.getYear();
        cout<<"年第";
        a.dayOfYear();
        cout<<""<<endl;
    }
    return 0;
}
main.cpp

2.

#ifndef INFO_H
#define INFO_H
#include<iostream>
#include<string>
#include<vector>
using namespace std;
class info{
public:
    info(string x,string y,string m,int n):nickname(x),contact(y),city(m),n(n){}
    void show(){
        cout<<"称呼:";
        cout<<nickname<<endl;
        cout<<"联系方式:";
        cout<<contact<<endl;
        cout<<"所在城市:";
        cout<<city<<endl;
        cout<<"预定参加人数:";
        cout<<n<<endl;
    }
private:
    string nickname;
    string contact;
    string city;
    int n;
};

#endif
info.h
#include<iostream>
#include"info.h"
#include<vector>
using namespace std;
int main()
{    
    vector<info>infos;
    string x,y,m;
    int n,i,j=0;
    cout<<"录入信息:"<<endl;
    cout<<"称呼,联系方式,所在城市,预定参加人数"<<endl;
    while(cin>>x>>y>>m>>n)
    {
        info ljh(x,y,m,n);
            j++;
        infos.push_back(ljh);
    }
    for(i=0;i<j;i++)
        infos[i].show();
    system("pause");
    return 0;
}
main.cpp

posted on 2019-04-30 15:06  式武神  阅读(99)  评论(0编辑  收藏  举报