Best Industrial Training in C,C++,PHP,Dot Net,Java in Jalandhar

Monday 22 July 2013

Program in C++ to find addition of time in hours and mintues

#include<iostream>
using namespace std;
class Time
{
private:
int h,m;
public:
void get(int x,int y)
{
h=x;
m=y;
}
void disp()
{
cout<<h<<":"<<m<<"\n";
}
void add(Time t1,Time t2)
{
m=t1.m+t2.m;
h=m/60;

m=m%60;
h=h+t1.h+t2.h;
}
};
int main()
{
Time t1;
t1.get(3,45);
Time t2;
t2.get(2,30);
Time t3;

t3.add(t1,t2);
t1.disp();
t2.disp();
t3.disp();
return 0;

}


Output:
Executing the program....

3:45
2:30
6:15

No comments:

Post a Comment