0% found this document useful (0 votes)
49 views1 page

Object As Argument

The document contains code for a Time class in C++ with methods to set time, output time, and sum two Time objects. It defines default, single parameter, and two parameter constructors. The sum method calculates the sum of two Time objects and outputs the result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
49 views1 page

Object As Argument

The document contains code for a Time class in C++ with methods to set time, output time, and sum two Time objects. It defines default, single parameter, and two parameter constructors. The sum method calculates the sum of two Time objects and outputs the result.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

#include<iostream.

h>
#include<conio.h>

class Time
{
int hour;
int minute;
public:
/* void getData(int h,int m)
{
hour=h;
minute=m;
}*/
Time() //default constructor
{
hour=0;
minute=0;
}
Time(int n)
{
hour=minute=n;
}
Time(int h,int m)
{
hour=h;
minute=m;
}
void putData()
{
cout<<hour<<" Hour and "<<minute <<" Minutes "<<endl;
}
void sum(Time T2);
};
void Time::sum(Time T2)
{
Time T3;
T3.minute=minute+T2.minute;
T3.hour=T3.minute/60;
T3.minute=T3.minute%60;
T3.hour=T3.hour+hour+T2.hour;
cout<<T3.hour<<" Hour and "<<T3.minute <<" Minutes "<<endl;
}
int main()
{
clrscr();
Time T1(5,50);
Time T2(4,20); //T3=T1+T2;
T1.putData();
T2.putData();
T1.sum(T2);
getch();
return 0;
}

You might also like