#include <iostream>
using namespace std;

class Time {
private:
    int hour, minute, second;
public:
    Time(int h = 0, int m = 0, int s = 0) : hour(h), minute(m), second(s) {}
    Time operator++(); //前自增
    void display() { cout << hour << ":" << minute << ":" << second << endl; }
};

Time Time::operator++() {
    second++;
    if (second == 60) {
        second = 0;
        minute++;
        if (minute == 60) {
            minute = 0;
            hour++;
            if (hour == 24) {
                hour = 0;
            }
        }
    }
    return *this;
}

int main() {
    Time t(23, 59, 50);
    for (int i = 0; i < 10; i++) {
        ++t;
        t.display();
    }
    return 0;
}
``
设计Time类如下要求其中重载前自增++。模拟秒表每次走一秒满60秒进位秒又从零开始计数。满60分进位分又从零开始计数。输出时、分和秒的值。

原文地址: https://www.cveoy.top/t/topic/hoXe 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录