Question: 2. Coding Problem We already overloaded the 't' operator last session such that it adds two Time class objects. In this session, you are required




2. Coding Problem We already overloaded the 't' operator last session such that it adds two Time class objects. In this session, you are required to further overload the '+'operator as follows: - The new overloaded '+'operator adds a Time class object to an int. The integer operand represents seconds. It should be validated to be less than 86,400 sec (24 hours). If larger or equal, you should print "Too big operand for '+' operator" and stop the program immediately (exit(-1);) The new overloaded 't' operator is commutative, i.e., it works both ways: Time + int and int + Time. The function should add the int parameter value, as seconds, to the Time object parameter. Hint 1: If you convert the int parameter (seconds) to hours, minutes and seconds, you can reuse the exact same code you developed during last lab's session to add two objects of type Time. Hint 2: To convert seconds to hours, minutes and seconds, note that 1 hour is 60 min and each min is 60 sec. You will need to use integer division (/)and remainder (%) of division by 60 appropriately. Hint 3: How many functions do you need to perform the required task? Can you do it with member functions? How many parameters do the functions need and what are their types? What is the type of the return value? Use the main() function code below as a tester. You are not allowed to modify it. Answer the following question: There are 3 occurrences of the 't' operator in the following code. Which operator function is called each time? // Main program: Do NOT modify!! int main() { Time t1(2,30,10), t2(3,15,35), tsum; tsum = 10000 + t1 + t2 + 20000; cout using namespace std; class Time private: int hrs; int min; int sec; public: Time(); Time (int, int, int); Time(); void sett(int, int, int); void gett(int&, int&, int&); void showt(); void incrt(); void decrt(); Time operator+(Time t2); }; Time: :Time() { hrs = ; min se; sec = ; } Time:: Time(int hh, int mm, int ss) { sett (hh, mm, ss); } Time:-Time() { } void Time::set(int hh, int mm, int ss) { if((hh>=0 && hh=0 && mm=0 && ss59) { sec = %; min++; if (min>59) { min = 0; hrs++; if (hrs>23) hrs=0; } } } void Time::decrt() { sec-- if (sec
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
