//constructor
overloading II
//econstr4.cpp
to demo multiple constructors.
#include<iostream.h>
#include<conio.h>
class time
{ int hrs;
int mins;
int secs;
public:
time() {hrs=0;mins=0;secs=0;}
time(int h,int m,int s);
time(long h) ;
void gettime();
void showtime();
};
main()
{
clrscr();
cout<< "econstr4.cpp
start" <<endl;
time t1; //----1----
cout<<"showing t1:";
t1.showtime();
time t2(9,15,0);
//----2----
cout<< "college opens
time t2";
t2.showtime();
time t3; //----3----
cout<<"lanch breack
starts time t3";
t3.showtime();
time t4(51300); //----4----
cout<<"lunch breack
ends time t4";
t4.showtime();
time t5 = time(17,15,0); //----5----
cout<<"the day ends time
t5";
t5.showtime();
getch();
return 0;
}
time :: time(int
h,int m,int s)
{
hrs = h; mins = m; secs = s;
}
time ::
time(long h)
{
long temp;
secs = h % 60;
temp =h/ 60;
mins = temp % 60;
hrs = temp / 60;
}
void
time::gettime()
{
cout<<"enter time as hh mm ss:";
cin>> hrs >> mins
>>secs;
}
void time ::
showtime()
{
cout<< hrs
<< ':' << mins <<':' << secs <<endl;
}