Prog 28 Write a program for the addition of time in hour and minute format by using object as argument.
#include<iostream.h>
#include<conio.h>
class time
{
public:
int hour;
int min;
void getdata(int x,int y)
{
hour=x;
min=y;
}
void display()
{
cout<<"\n hours ="<<hour;
cout<<"\n minute ="<<min;
}
void sum(time,time);
};
void time::sum(time t1,time t2)
{
min=t1.min+t2.min; hour=min/60; min=min%60;
hour=hour+t1.hour+t2.hour;
}
void main()
{
clrscr();
time t1,t2,t3; t1.getdata(2,45); t2.getdata(3,40); t3.sum(t1,t2); t1.display(); t2.display(); t3.display(); getch();
}
Output:
hours =2 minute =45 hours =3 minute =40 hours =6 minute =25
#include<iostream.h>
#include<conio.h>
class time
{
public:
int hour;
int min;
void getdata(int x,int y)
{
hour=x;
min=y;
}
void display()
{
cout<<"\n hours ="<<hour;
cout<<"\n minute ="<<min;
}
void sum(time,time);
};
void time::sum(time t1,time t2)
{
min=t1.min+t2.min; hour=min/60; min=min%60;
hour=hour+t1.hour+t2.hour;
}
void main()
{
clrscr();
time t1,t2,t3; t1.getdata(2,45); t2.getdata(3,40); t3.sum(t1,t2); t1.display(); t2.display(); t3.display(); getch();
}
Output:
hours =2 minute =45 hours =3 minute =40 hours =6 minute =25
No comments:
Post a Comment