首页 > 其他 > 详细

时间类--多重继承

时间:2014-06-05 01:58:03      阅读:363      评论:0      收藏:0      [点我收藏+]
/*
*Copyright (c) 2013, 烟台大学计算机学院
* All rights reserved.
* 作    者:马广明
* 完成日期:2014 年 5 月 19 日
* 版 本 号:v1.0
* 问题描述:日期时间类
*/
#include <iostream>

using namespace std;

class Date
{
public:
    Date(int y,int m,int d)
    {
        year=y;
        month=m;
        day=d;
    }
    void SetDate(int y,int m,int d)
    {
        year=y;
        month=m;
        day=d;
    }
    void PrintDate()
    {
        cout<<year<<"/"<<month<<"/"<<day<<'\t';
    }
protected:
    int year,month,day;
};
class Time
{
public:
    Time(int h,int m,int s)
    {
        hour=h;
        minute=m;
        second=s;
    }
    void SetTime(int h,int m,int s)
    {
        hour=h;
        minute=m;
        second=s;
    }
    void PrintTime()
    {
        cout<<hour<<":"<<minute<<":"<<second<<endl;
    }
protected:
    int hour,minute,second;
};

class TimeDate:public Date,public Time
{
public:
    TimeDate(int y=0,int mon=0,int d=0,int h=0,int min=0,int s=0):
        Date(y,mon,d),Time(h,min,s){}
    void PrintDate_Time()
    {
        PrintDate();
        PrintTime();
    }
};

int main()
{
    TimeDate dt_a,dt_b(2014,5,20,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;
}

bubuko.com,布布扣

时间类--多重继承,布布扣,bubuko.com

时间类--多重继承

原文:http://blog.csdn.net/u012369134/article/details/27200549

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!