Timetype 终于成功了
luyued 发布于 2011-01-14 18:42 浏览 N 次**************************************************************************
class Time
{
public:
void Set(int hours, int minutes,int seconds);
void Increment();
void Write() const;
bool Equal(Time otherTime)const;
bool LessThan(Time otherTime) const;
Time(int initHrs ,int initMins,int initSecs);
Time();
private:
int hrs;
int mins;
int secs;
};
*******************************************************************************
#include"Time.h"
#include
using namespace std;
void Time::Set(int hours,int minutes,int seconds)
{
hrs=hours;
mins=minutes;
secs=seconds;
}
void Time::Increment()
{
secs++;
if (secs>59)
{
secs=0;
mins++;
if(mins>59)
{
mins=0;
hrs++;
if(hrs>23)
hrs=0;
}
}
}
void Time::Write() const
{
if (hrs<10)
cout<<'0';
cout< if (mins<10)
cout<<'0';
cout<
cout<<'0';
cout<
bool Time::Equal(Time otherTime) const
{
return(hrs==otherTime.hrs && mins== otherTime.mins && secs==otherTime.secs);
}
bool Time::LessThan(Time otherTime) const
{
return(hrs
&& secs< otherTime.secs);
}
Time::Time(int initHrs ,int initMins,int initSecs)
{
hrs=initHrs;
mins=initMins;
secs=initSecs;
}
Time::Time()
{
hrs=0;
mins=0;
secs=0;
}
************************************************************************
#include"Time.h"
#include
using namespace std;
void main()
{
Time time1(5,30,0);
Time time2;
int loopcount;
cout<<"time1"; time2=time1; if(time1.Equal(time2)) time2.Increment(); if(time1.LessThan(time2)) if(time2.LessThan(time1)) time1.Set(23,59,55);
time1.Write();
cout<<" time2";
time2.Write();
cout<
cout<<"Times are equal"<
cout<<"Times are NOT equal"<
cout<<"time1:";
time1.Write();
cout<<" time2:";
time2.Write();
cout<
cout<<"Times are equal"<
cout<<"Times are NOT equal"<
cout<<"New time2:";
time2.Write();
cout<
cout<<"time1 is less than time2 "<
cout<<"time1 is NOT less than time2 "<< endl;
cout<<"time2 is less than time1 "<
cout<<"time2 is NOT less than time1 "<< endl;
cout<<"Incrementing time1 from 23:59:55 "<
time1.Write();
cout<<' ';
time1.Increment();
cout<
cout<
MSN空间完美搬家到新浪博客!
- 07-01· 禁教唐诗算术能还幼儿快
- 07-01· 2011年06月17日
- 07-01· 唐诗宋词英译:李商隐 筹
- 07-01· 仿评《唐诗1000首》第186首
- 07-01· 没事干的时候背背唐诗吧
- 07-01· [转载]唐诗中“斜”字该读
- 07-01· 湖南醴陵瓷业转型升级
- 07-01· 奇瑞风云2两厢黑色|2010款
- 07-01· 摩根士丹利华鑫摩根士丹
- 07-01· 摩根士丹利华鑫近期优选
- 07-01· 中金投行部大摩出售中金
- 07-01· 摩根士丹利招聘6月2日【实
- 07-01· 营养防病圣典
- 07-01· 《博伽梵歌原意》之第十
- 07-01· [不错]斑斓圣典---减肥中常
- 07-01· 武乐圣典《太极武当》:武
- 07-01· 铁血英雄-现阶段战功牌兑
- 07-01· 2011年06月10日【原创】南歌
- 07-01· 【淘宝网信息】- 2010年的
- 07-01· 深圳品牌女装有哪些?