HOME

Tuesday, September 22, 2015

CALCULATING TIME BY PASSING ONJECT AS THE FUNCTION ARGUMENT

#include<iostream>
using namespace std;
class time
{
    int hour, minute, second;
public:
    void getdata()
    {
        cout<<"Enter the hour"<<endl;
        cin>>hour;
        cout<<"Enter the minute"<<endl;
        cin>>minute;
        cout<<"Enter the second"<<endl;
        cin>>second;
    }
    void display(time t1, time t2)
    {
        second=t1.second+t2.second;
        minute=second/60;
        second%=60;
        minute=minute+t1.minute+t2.minute;
        hour=minute/60;
        minute%=60;
        hour=hour+t1.hour+t2.hour;

        cout<<"The total time is "<<endl;
        cout<<hour<<" hour "<<minute<<" minute "<<second<<" second "<<endl;
    }
};
int main()
{
    time t1,t2,t3;
    t1.getdata();
    t2.getdata();
    t3.display(t1,t2);
    return 0;
}

No comments:

Post a Comment