Search This Blog

Monday, December 23, 2013

Objects as function arguements

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

    }
};
int  main()
{
    time t1, t2, t3;
    cout<<" enter start time : ";
    t1.input();
    cout<<" enter end time : ";
    t2.input();
    t3.add(t1,t2);
    t3.display();
    return 0;
}

No comments:

Post a Comment