24小时热门版块排行榜    

查看: 1826  |  回复: 7
本帖产生 1 个 程序强帖 ,点击这里进行查看
当前只显示满足指定条件的回帖,点击这里查看本话题的所有回帖

libralibra

至尊木虫 (著名写手)

骠骑将军

【答案】应助回帖

★ ★ ★ ★ ★
jjdg(金币+2): 辛苦了 2011-06-25 11:22:21
余泽成(金币+3, 程序强帖+1): 谢谢参与应助! 2011-06-26 00:19:14
wuyan070987(金币+5): 2011-07-07 20:13:36
随便写下
CODE:
#include
using namespace std;

class Date
{
public:
    int year, month, day;

    Date()
    { this->year = this->month = this->day = 0; }

    Date(int y, int m, int d)
    {
        this->year = y;
        this->month = m;
        this->day = d;
    }

    void Show()
    {
        cout << "Date: " << this->day << "/" << this->month << "/" << this->year << endl;
    }
};

class Time
{
public:
    int hour,minute,second;

    Time()
    { this->hour = this->minute = this->second = 0; }

    Time(int h, int m, int s)
    {
        this->hour = h;
        this->minute = m;
        this->second = s;
    }

    void Show()
    {
        cout << "Time: " << this->hour << ":" << this->minute << ":" << this->second << endl;
    }
};

class DateTime : public Date, public Time
{
public:
    DateTime()
    { ; }

    DateTime(int y, int m, int d, int h, int min, int s)
    {
        this->year = y; this->month = m; this->day = d;
        this->hour = h; this->minute = min; this->second = s;
    }

    ~DateTime() {;}

    void Show()
    {
        cout << "DateTime: "
                << this->day << "/" << this->month << "/" << this->year << " "
                << this->hour << ":" << this->minute << ":" << this->second << endl;
    }
};

int main(int args, char* argv[])
{
    Date dt = Date(2011,6,25);
    Time tm = Time(10,10,10);
    DateTime dtm = DateTime(2011,6,25,10,10,10);

    dt.Show();
    tm.Show();
    dtm.Show();

    return 0;
}

结果
CODE:
Date: 25/6/2011
Time: 10:10:10
DateTime: 25/6/2011 10:10:10

Process returned 0 (0x0)   execution time : 0.328 s
Press any key to continue.

matlab/VB/python/c++/Java写程序请发QQ邮件:790404545@qq.com
2楼2011-06-25 06:27:05
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖

智能机器人

Robot (super robot)

我们都爱小木虫

相关版块跳转 我要订阅楼主 wuyan070987 的主题更新
信息提示
请填处理意见