3 ms·
Ask HN: How does “min” and “hour” get their values in this C++ code?
https://imgur.com/a/UCks0vq
Full code here:
#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.
- bunbun69 4y agoI have no clue what this post is doing here.
- popcalc 4y agoYesterday I had an "AI researcher" at Ericsson ask me if I could teach him "how to code". HN, like tech in general has recently had a bunch of hustlers who would otherwise be selling you timeshares jump along for the hype train. I'm trying to find an explanation for the recent spike in posts like OP that lack an understanding of the site/community's etiquette.
- shivajikobardan 4y agoare programming questions not allowed in hn?
- bunbun69 4y agoIt's very low effort, StackOverflow and Reddit will probably delete the question as well
- pestatije 4y agostackoverflow is your friend
- shivajikobardan 4y agoI don't think SO will like these kinds of questions. It's barely any good for learning concepts unlike HN. Most of stuffs there is rote memorization(related to concepts).
- Abby0 4y agoI think the point being is HN isn't not the place to ask for technical help in this manner.