您的位置:首页 > 服装鞋帽 > 女装 > Timetype 终于成功了

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< if (secs<10)
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 hrs==otherTime.hrs && mins hrs==otherTime.hrs && mins==otherTime.mins
&& 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";
time1.Write();
cout<<" time2";
time2.Write();
cout< if(time1.Equal(time2))
cout<<"Times are equal"< else
cout<<"Times are NOT equal"<

time2=time1;
cout<<"time1:";
time1.Write();
cout<<" time2:";
time2.Write();
cout<

if(time1.Equal(time2))
cout<<"Times are equal"< else
cout<<"Times are NOT equal"<

time2.Increment();
cout<<"New time2:";
time2.Write();
cout<

if(time1.LessThan(time2))
cout<<"time1 is less than time2 "< else
cout<<"time1 is NOT less than time2 "<< endl;

if(time2.LessThan(time1))
cout<<"time2 is less than time1 "< else
cout<<"time2 is NOT less than time1 "<< endl;

time1.Set(23,59,55);
cout<<"Incrementing time1 from 23:59:55 "< for(loopcount=1;loopcount<=100;loopcount++){
time1.Write();
cout<<' ';
time1.Increment();
cout< }
cout< }


MSN空间完美搬家到新浪博客!

图文资讯
广告赞助商