时间类
#include<iostream>
using namespace std;
class Date
{
public:
    void SetDate(int y,int m,int d)
    {
        Year=y;
        Month=m;
        Day=d;
    }
    void PrintDate()
    {
        cout<<Year<<"/"<<Month<<"/"<<Day;
    }
    Date():Year(0),Month(0),Day(0) {}
    Date(int y,int m,int d):Year(y),Month(m),Day(d) {}


private:
    int Year,Month,Day;
};
class Time
{
public:
    void SetTime(int h,int m,int s)
    {
        Houre=h;
        Minutes=m;
        Seconds=s;
    }
    void PrintTime()
    {
        cout<<Houre<<":"<<Minutes<<":"<<Seconds;
    }
    Time():Houre(0),Minutes(0),Seconds(0) {}
    Time(int h,int m,int s):Houre(h),Minutes(m),Seconds(s) {}


private:
    int Houre,Minutes,Seconds;
};
class TimeDate: public Date,public Time
{
public:
    TimeDate():Date(),Time() {};
    TimeDate(int y,int mo,int d,int h,int mi,int s):
        Date(y,mo,d),Time(h,mi,s) {}
    void PrintDate_Time()
    {
        PrintDate();
        cout<<" ";
        PrintTime();
    }
};
int main()
{
    TimeDate dt_a,dt_b(2010,4,16,9,30,0);
    cout<<"dt_a: ";
    dt_a.PrintDate_Time();
    cout<<endl;
    cout<<"dt_b: ";
    dt_b.PrintDate_Time();
    dt_a.SetTime(20,00,00);
    dt_a.SetDate(2008,8,7);
    cout<<endl;
    cout<<"dt_after uptate: ";
    dt_a.PrintDate_Time();
    return 0;
}
阅读更多
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

时间类

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭