Другие языки программирования и технологии

задача по программированию (электронные часы) С++

электронные часы показывают время : м часы (от 0 до 23), n минуты (от 0 до 59) k секунды (от 0 до 59) Какое время будут показывать часы через p часов q минут r секунд.
Самостоятельный ввод всех переменных, спасибо
#include <iostream>
#include <tuple>
#include <string>
using namespace std;
class Time {
public:
Time(int h, int m, int s) : ts_(h * hour + m * ms + s) {
normalize();
}
void add(int h, int m, int s) {
ts_ += h * hour + m * ms + s;
normalize();
}
tuple<int, int, int> get()const {
auto h = ts_ / hour;
auto s = ts_ % ms;
auto m = (ts_ - s - h * hour) / ms;
return { h, m, s };
}
private:
int ts_;
static const auto day = 86400;
static const auto hour = 3600;
static const auto ms = 60;
void normalize() {
while (ts_ > day) ts_ -= day;
}
friend ostream& operator<<(ostream& out, const Time& time) {
auto[hh, mm, ss] = time.get();
const auto x = 10;
if (hh < x) out.put('0');
cout << hh << ':';
if (mm < x) out.put('0');
cout << mm << ':';
if (ss < x) out.put('0');
cout << ss;
return out;
}
};
int get(const char* msg) {
int number;
string buffer;
while (true) {
cout << msg << ": ";
cin >> buffer;
try {
number = stoi(buffer);
} catch (...) {
continue;
}
if (number >= 0) break;
}
return number;
}
int main() {
setlocale(LC_CTYPE, "Russian");
auto hh = get("Часы");
auto mm = get("Минуты");
auto ss = get("Секунды");
Time time(hh, mm, ss);
cout << time << '\n';
auto p = get("Часы");
auto q = get("Минуты");
auto r = get("Секунды");
time.add(p, q, r);
cout << time << '\n';
system("pause");
}
Олег Фролов
Олег Фролов
60 230
Лучший ответ
Александр Рогозный А есть ли разница в инициализации:

Time(int h, int m, int s) : ts_(h * hour + m * ms + s) {
normalize();
}

или

Time(int h, int m, int s){
ts_ = h * hour + m * ms + s;
normalize();
}
И если есть разница то не уточните какая? Не понимаю зачем нужна первая инициализация.