📄 time.cpp
字号:
// Time.cpp: implementation of the Time class.
//
//////////////////////////////////////////////////////////////////////
#include "Time.h"
//////////////////////////////////////////////////////////////////////
Time::Time():hour(0),minute(0),second(0)
{ }
Time::Time( unsigned h,unsigned m,unsigned s )
{ setTime( h, m, s ); }
Time::Time( const Time& t )
{ setTime( t.hour,t.minute,t.second ); }
Time::Time( char* t )
{
unsigned h=0,m=0,s=0;
char ch;
istrstream tStream(t);
tStream>>h>>ch>>m>>ch>>s;
setTime( h, m, s );
}
void Time::setTime( unsigned h,unsigned m,unsigned s ){
if( h<25 && m<60 && s<60 )
{ hour=h; minute=m; second=s; }
else{
cerr<<"invalid time format"<<endl;
hour=minute=second=0;
}
}
Time::~Time()
{}
bool Time::operator == (const Time& t)
/* If two date all the same then return true, else return false.*/
{ return hour==t.hour && minute==t.minute && second==t.second; }
bool Time::operator > (const Time& t)
/* If the first time later than the follow, return true *
* else return false. */
{
return hour>t.hour
|| hour==t.hour && minute>t.minute
|| minute==t.minute && second>t.second;
}
bool Time::operator < (const Time& t)
/* If the first time earlier than the follow , return true *
* else return false. */
{
return hour<t.hour
|| hour==t.hour && minute<t.minute
|| minute==t.minute && second<t.second;
}
istream& operator>> ( istream& is,Time& t)
{
unsigned hour=0,minute=0,second=0;
char ch;
is>>hour>>ch>>minute>>ch>>second;
t.setTime( hour,minute,second );
return is;
}
ostream& operator << ( ostream& os, Time& t)
{
os<<t.hour<<':'<<t.minute<<':'<<t.second;
return os;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -