c++:定义一个time类,该类对时、分、秒进行封装

要求:
(1)定义带参的构造函数,并通过初始化成员列表的形式对类的数据成员进行初始化
(2)定义display()成员函数,用来输出数据成员的值。
(3)编写主函数,对上述功能进行测试。

#include <iostream>
using namespace std;

class Time
{
public:
    Time(int hour, int minute, int second)
        :m_hour(hour), m_minute(minute), m_second(second)
    {}
    void display()
    {
        if (m_hour < 10) cout << 0;
        cout << m_hour << ":";
        if (m_minute < 10) cout << 0;
        cout << m_minute << ":";
        if (m_second < 10) cout << 0;
        cout << m_second << endl;
    }
private:
    int m_hour, m_minute, m_second;
};
int main()
{
    Time t1(9,29,5);
    t1.display();
    return 0;
}

#include <iostream>
using namespace std;

class Time
{
public:
    Time(int h, int m, int s):hour(h), m(m), s(s){}
    void display()
    {
        cout << hour << ":" << minute << ":" << second << endl;
    }
private:
    int hour, minute, second;
};
int main() {
    Time t(9,29,5);
    t.display();
    return 0;
}