Open Diliphindustani opened 1 year ago
Missing Implementation of setTime(): The setTime() function is declared but not defined. You need to implement this function to allow the user to input time values. Incorrect Return Statement in operator+: In the operator+ function, you are returning t1 instead of the newly created t. This means the result of the addition is not being returned correctly. Time Format Handling: The handling of hours should consider a 24-hour format or a 12-hour format correctly. The current implementation uses % 12, which may not be appropriate for all cases. With these changes, your program should compile and run correctly, allowing the user to input two times and then output their sum. The time is handled in a normalized manner, ensuring that the output is valid.
include
using namespace std;
class Time {
int h, m, s; public:
Time()
{ h = 0, m = 0, s = 0;
}
};
void Time::setTime() { char tim[9]; std::cin>>tim; int hh; int mm; int ss;
}
Time Time::operator+(Time t1) {
Time t;
int a, b;
a = this->s + t1.s;
t.s = a % 60;
b = (a / 60) + this->m + t1.m;
t.m = b % 60;
t.h = (b / 60) + this->h + t1.h;
t.h = t.h % 12;
return t; }
/*---------------------------------------------------------------------------------------------------------------- ──(shiv㉿kali)-[~/GIT_REPOS/online_c++_questions] └─$ ./a.out
enter the first time hh:mm:ss10:13:45
Enter the second time13:45:56
first time10:13:45 second time13:45:56 sum of times11:59:41
┌──(shiv㉿kali)-[~/GIT_REPOS/online_c++_questions] └─$ ./a.out enter the first time hh:mm:ss01:12:23
Enter the second time03:04:05
first time1:12:23 second time3:4:5 sum of times4:16:28
---------------------------------------------------------------------------------*/