hi i have a problem with another class problem.
i have this code so far but i am getting a few problems
1] it comes up with 2 times and i dont want that
2] i would like it so output seconds
3]T3 = T1.Add(T2); T2 is added to T1 and the result returned is the sum of the two times which is assigned to T3.
4]Will initialise the object T1 to 15:20:35.
at the moment i have not managed to get it into a function or add the 2 times to to output T3.
can anyone help?
here is my code
Code:
#include <iostream>
using namespace std;
class Time
{
public:
Time();
Time(int hours2, int minutes2);
int getHours() const;
int getMinutes() const;
void setHours(const int hours2);
void setMinutes(const int minutes2);
Time operator+(const Time &t1) const;
void show() const;
private:
int hours, minutes;
};
Time::Time()
{
hours = minutes=0;
}
Time::Time(int hours2, int minutes2)
{
hours = hours2;
minutes = minutes2;
}
int Time::getHours() const
{
return hours;
}
int Time::getMinutes() const
{
return minutes;
}
void Time::setHours(const int hours2)
{
hours = hours2;
}
void Time::setMinutes(const int minutes2)
{
minutes = minutes2;
}
Time Time::operator+(const Time &t1) const
{
Time sum;
sum.minutes = minutes + t1.minutes;
sum.hours = hours + t1.hours + sum.minutes/60;
sum.minutes %=60;
return sum;
}
void Time::show() const
{
cout<<hours<<":"<<minutes<<endl;
}
int main()
{
Time t1;
Time t2;
Time t3;
t1.setHours(2);
t2.setMinutes(25);
t3.show();
t3 = t1 + t2;
t3.show();
system("pause");
}