封装-定义电子时钟类

#include<bits/stdc++.h>

using namespace std;

class Clock {

private:

int Hour;

int Minute;

int Second;

public:

Clock(int h = 0, int m = 0, int s = 0) : Hour(h), Minute(m), Second(s) {}

void setTime(int h, int m, int s) {

Hour = h;

Minute = m;

Second = s;

}

void displayTime() {

cout << setw(2) << setfill('0') << Hour << ":"

<< setw(2) << setfill('0') << Minute << ":"

<< setw(2) << setfill('0') << Second << endl;

}

};

int main() {

int h, m, s;

cin >> h >> m >> s;

Clock clock;

clock.setTime(h, m, s);

clock.displayTime();

return 0;

}

全部评论

相关推荐

01-15 19:59
中山大学 C++
牛客60887332...:你这是人写出来的? 本科标到硕士后面 留那么多空给 hr 填?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务