HACKER Q&A
📣 shivajikobardan

How does “min” and “hour” get their values in this C++ code?


https://imgur.com/a/UCks0vq

Full code here:

    #include
    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<
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 Accepted Answer ✓
I have no clue what this post is doing here.

👤 pestatije
stackoverflow is your friend