I have a task to implement the overloading of the operators: -- (pre and postfix), -, -=, <, <=, >, >=, == and !=. I have managed to do most of these, but I am having trouble with the -= operator. The Time object has member variables of hour, min and sec. Operator-= should subtract n number of seconds from the Time object.
where n = 30
You can't assume that if n > sec (i.e., sec -= n goes negative) that you will only need to subtract 1 from the minute. What if you're subtracting 1000 seconds? Or 10000 seconds? There's 86400 seconds in a day.
It's probably best to do such calculations by converting your hour, min, sec form to number of seconds since midnight, subtract n from that, and then convert back. In fact, it would probably be best to store the time as the number of seconds since midnight in the first place. But maybe you don't want to do that.
And I don't agree with limiting n to an unsigned value. I think you should be able to subtract a negative value.