Image

C++ - Object - Object as function arguments

Object as function arguments

It is possible to send object as arguments to the function just like any other variable send to the function.

e.g: WAP for object as function argument
#include<iostream.h>
#include<conio.h>
class Time
{
  public:
	  int hr,mn;
  public:
	  void set(int a,int b)
	  {
	   hr=a;
	   mn=b;
	  }
	  void show()
	  {
	   cout<<"\nTime is "<<hr<<":"<<mn;
	  }
};
void addTime(Time t1,Time t2)
{
 int h,m;
 m=t1.mn+t2.mn;
 h=m/60;
 m=m%60;
 h=t1.hr+t2.hr+h;
 cout<<"\n Total time = "<<h<<":"<<m;
}
void main()
{
 Time t1,t2;
 clrscr();
 t1.set(3,42);
 t2.set(4,40);
 cout<<"T1 = "<<t1.hr<<":"<<t1.mn<<endl;
 cout<<"T2 = "<<t2.hr<<":"<<t2.mn<<endl;
 addTime(t1,t2);
 getch();
}