You can simplify operator+() somewhat.
- Use hasil directly instead of having separate hasil_second, hasil_minute and hasil_hour variables.
- Use the ++ and += operators: x++ means x = x + 1. x += y means x = x + y
Time operator+(const Time & t)
{
Time hasil(t); // make a copy of t
// Add my values to hasil. x += y is the same as x = x + y
hasil.hour += hour;
hasil.second += second;
hasil.minute += minute;
// Now normalize the values
if (hasil.second > 60) {
hasil.second -= 60;
hasil.minute++; // x++ is the same as x = x + 1
}
if (hasil.minute > 60) {
hasil.minute -= 60;
hasil.hour++;
}
return hasil;
}
};