The kitchen has a little 24-hour Clock. Write add(minutes) to move it on by minutes (0 or more). Every 60 minutes make another hour, and hour 24 goes back to 0. show() is already written and shows 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)#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) {
// your code here: move on by 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();
}
Run tries the examples. When they look right, Submit.