PROGRAM FOR OBJECT AS ARGUMENT

//program to use object as argument
#include<iostream.h>
#include<conio.h>
class time
{
  int h,m;
  public:
void getin(int H,int M)
{
 h=H;
 m=M;
}
void dis()
{
cout<<"hour="<<h<<endl;
cout<<"min="<<m<<endl;
}
void sum(time,time);
};
void time::sum(time t1,time t2)
{
  m=t1.m+t2.m;
  h=m/60;
  m=m%60;
  h=h+t1.h+t2.h;
}
void main()
{
 time a,b,c;
 clrscr();
 a.getin(2,45);
 b.getin(3,45);
 c.sum(a,b);
 a.dis();
 b.dis();
 c.dis();
 getch();
}

Comments

Popular Posts