Getting compilation error in this c++ program
#include <iostream>
using namespace std;
class Time
{
int h, m, s;
public:
Time()
{
h = 0, m = 0, s = 0;
}
void setTime();
void show()
{
cout << h << ":" << m << ":" << s;
}
Time operator+(Time);
};
Time Time::operator+(Time t1)
{
Time t;
int a, b;
a = s + t1.s;
t.s = a % 60;
b = (a / 60) + m + t1.m;
t.m = b % 60;
t.h = (b / 60) + h + t1.h;
t.h = t.h % 12;
return t1;
}
int main()
{
Time t1, t2, t3;
cout << "enter the first time";
t1.setTime();
cout << "\n Enter the second time";
t2.setTime();
t3 = t1 + t2;
cout << "\n first time";
t1.show();
cout << "\nsecond time";
t2.show();
cout << "\n sum of times";
t3.show();
return 0;
}
#420
class Time {
int h, m, s;
public:
Time()
{ h = 0, m = 0, s = 0;
}
void setTime();
void show() {
cout << h << ":" << m << ":" << s;
}
Time operator+(Time);
};
void Time::setTime()
{
char tim[9];
std::cin>>tim;
int hh;
int mm;
int ss;
hh = atoi(&tim[0]);
mm = atoi(&tim[3]);
ss = atoi(&tim[6]);
this->h=hh;
this->m=mm;
this->s=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; }
int main() {
Time t1, t2, t3;
cout << "enter the first time hh:mm:ss";
t1.setTime();
cout << "\n Enter the second time";
t2.setTime();
t3 = t1 + t2;
cout << "\n first time";
t1.show();
cout << "\nsecond time";
t2.show();
cout << "\n sum of times";
t3.show();
return 0;
}
/*----------------------------------------------------------------------------------------------------------------
──(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
---------------------------------------------------------------------------------*/
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
---------------------------------------------------------------------------------*/