Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
1.2 kB
0
Indexable
Never
// Online C++ compiler to run C++ program online
#include <iostream>
using namespace std;
class time
{
    int hr,min,sec;
   pubilc:
    void input()
    {
        cout<<"enter hour,minute,sec";
        cin>>hr>>min>>sec;
        
    }
    void display()
    {
        cout<<hr<<"hour"<<min<<"minute"<<sec<<"second"<<endl;
        
    }
    void add(time t1,time t2)
    {
        sec=t1.sec+t2.sec;
        min=t1.min+t2.min+sec/60;
        sec=sec%60;
        hr=t1.hr+t2.hr+min/60;
        min=min%60;
        
        
    }

    void subtract(time t1,time t2)
    {
        min=0;
        hr=0;
        sec=t2.sec-t1.sec;
        if(sec<0)
        {
            sec=sec+60;
            min=min-1;
            
        }
        min=min+t2.min-t1.min;
        if(min<0)
        {
            min=min+60;
            hr=hr-1;
            
        }hr=hr+t2.hr-t1.hr;
        
    }
};

int main()
{
    time t1,t2,t3,t4;
    t1.input();
    t2.input();
    t3.input(t1,t2);
    cout<<endl<<"the addition of two time is:";
    t3.display();
    t4.subtract(t1,t2);
    cout<<endl<<"the subtraction of two time is:";
    t4.display();
    return 0;
    
    
}