
public:
void Set(int hours, int minutes, int seconds);
void Increment();
void Write() const;
bool Equal(TimeType otherTime) const;
bool LessThan(TimeType otherTime) const;
private:
int hrs;
int mins;
int secs;
};
void TimeType::Set(int hours, int minutes, int seconds)
{
hrs = hours;
mins = minutes;
secs = seconds;
}
void TimeType::Increment()
{
secs++;
if (secs>59) {
secs=0;
mins++;
if (mins>59) {
mins=0;
hrs++;
if (hrs>23) hrs=0;
}
}
}
void TimeType::Write() const
{
if (hrs<10) cout << ‘0’;
cout << hrs << ‘:’;
if (mins<10) cout <<‘0’;
cout << mins << ‘:’;
if (secs<10) cout <<‘0’;
cout << secs;
}
bool TimeType::Equal(TimeType otherTime) const
{
return (hrs==otherTime.hrs && mins==otherTime.mins && secs==otherTime.secs);
}
bool TimeType::LessThan(TimeType otherTime) const
{
return (hrs
怎么调用Equal(TimeType otherTime)和LessThan(TimeType otherTime)函数
TimeType ob;
TimeType ob2;
if(ob.Equal(ob2))
{
cout << "两者相等的结果" << endl;
}
if(ob.LessThan(ob2))
{
cout <<败厅 "ob小于察亏隐ob2的结果" << endl;
}
备注:
楼主只问空高怎么调用,不知道上诉介绍能解决问题不,不行的话可以追问!
TimeType time1, time2;
time1.Set(1, 2, 3);
time2.Set(2, 3 4);
if ( time1.Equal( time2 ) )
cout << "旦槐卜equal";
else if ( time1.LessThan( time2 ) )
cout <模穗<明孝 "less";