一段有深思的代码,c++

#include<iostream>
using namespace std;
class CTimeType
{
    int hour,minute,second;
public:
    CTimeType(int h=2,int m=0,int s=0)
    {
        hour=h;
        minute=m;
        second=s;
    }
    void display()
    {
        cout<<hour<<":"<<minute<<":"<<second<<endl;
    }
    void SetTime(int h,int m,int s)
    {
        hour=h;
        minute=m;
        second=s;
    }
};

class CDateType
{
    int month,day,year;
public:
    CDateType(int mon=1,int d=1,int y=2008)
    {
        month=mon;
        day=d;
        year=y;
    }

CDateTimeType(int mon=1,int d=1,int y=2000,int h=0,int m=0,int s=0):CDateType(mon,d,y),CTimeType(h,m,s)
    {
    
    }

    void display()
    {
        cout<<month<<"/"<<day<<"/"<<year<<endl;
    }
    void SetDate(int mon,int d,int y)
    {
        month=mon;
        day=d;
        year=y;
    }
};

class CDateTimeType:public CDateType,public CTimeType
{
public:
    CDateTimeType(int mon=1,int d=1,int y=2000,int h=0,int m=0,int s=0)
    {
        cout<<h<<endl;
        cout<<m<<endl;
        cout<<s<<endl;
        CDateType(mon,d,y);
        CTimeType(h,m,s);
    }
    void display()
    {
        CDateType::display();
        CTimeType::display();
    }
};

int main()
{
    cout<<"类的多重继承演示"<<endl;
    CDateTimeType dt(1,1,2008,11,13,12);
    cout<<"调用CDateTimeType类构造函数设定的初始日期,时间为:"<<endl;
    dt.display();
    dt.SetDate(8,8,2008);
    dt.SetTime(20,8,8);
    cout<<"调用基类成员函数修改后的时间,日期为:"<<endl;
    dt.display();
    return 0;
}

转载于:https://my.oschina.net/u/2246514/blog/682307

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值