Kodewick
学びはじめる →
ミニチャレンジ←→0 / 60

キッチンの時計

#045ミニチャレンジminute >= 60約 7 分

キッチンには 24 時間制の小さな Clock があります。時計を minutes 分(0 以上)進める add(minutes) を書きましょう。60 分ごとに 1 時間増え、24 時は 0 時に戻ります。show() はもう書いてあり、09:15 のように表示します。

例
clock_after(8, 30, 45)→'09:15'
clock_after(23, 50, 20)→'00:10'
関数string clock_after(int h, int m, int minutes)
main.cpp
#include <string>
using namespace std;

string two(int x) {
    string s = to_string(x);
    if (x < 10) {
        s = "0" + s;
    }
    return s;
}

class Clock {
public:
    int hour;
    int minute;

    Clock(int h, int m) {
        hour = h;
        minute = m;
    }

    void add(int minutes) {
        // ここにコードを書く:minutes 分進める
    }

    string show() const {
        return two(hour) + ":" + two(minute);
    }
};

string clock_after(int h, int m, int minutes) {
    Clock c(h, m);
    c.add(minutes);
    return c.show();
}
Ctrl + Enter でも実行できます
結果

実行すると例で試せます。よさそうなら提出しましょう。