- #1
shivajikobardan
- 674
- 54
- Homework Statement
- How does "min" and "hour" get their values in this C++ code?
- Relevant Equations
- none but I am studying about operator overloading although this is not operator overloading.
How does "min" and "hour" get their values in this C++ code?
Full code here:
<Moderator's note: Please use CODE tags when posting code.>
As shown in the figure above, some of my confusions are clear. But what I fail to understand is how "min" and "hour" gets its value from t2(8,40). I am sorry if this is a too basic question, but I didn't understand so I am asking.
If I am missing any prerequisites to this topic, do tell me about them, that'd help me more for self learning.
Full code here:
C++:
#include<iostream>
using namespace std;class Time
{
public:
int hour;
int min;
Time()
{
hour=min=0;
}
Time(int h,int m)
{
hour=h;
min=m;
}
Time add (Time t)
{
Time t1;
int m=min+t.min;
t1.hour=hour+t.hour+m/60;
t1.min=m%60;
return t1;
}
};
int main()
{
Time t1;
Time t2(8,40);
Time t3(5,30);
t1=t2.add(t3);
cout<<t1.hour<<" "<<t1.min;
return 0;
}
As shown in the figure above, some of my confusions are clear. But what I fail to understand is how "min" and "hour" gets its value from t2(8,40). I am sorry if this is a too basic question, but I didn't understand so I am asking.
If I am missing any prerequisites to this topic, do tell me about them, that'd help me more for self learning.