C++一个程序的问题
#include<iostream>usingnamespacestd;classtime24{public:time24(inth=0,intm=0,ints=0);v...
#include<iostream>
using namespace std;
class time24
{
public:
time24(int h=0,int m=0,int s=0);
void set_time(int h,int m,int s);
void get_time(int& h,int& m,int& s) const;
bool operator>(time24& t);
bool operator<(time24& t);
private:
int hours;
int minutes;
int seconds;
};
time24::time24(int h,int m,int s):
hours(h),minutes(m),seconds(s)
{}
void time24::set_time(int h,int m,int s)
{
hours=h;minutes=m;seconds=s;
}
void time24::get_time(int& h,int& m,int& s) const
{
h=hours;m=minutes;s=seconds;
}
bool time24::operator>(time24 & t)
{
if(hours>t.hours &&
minutes>t.minutes &&
seconds>t.seconds)
return true;
else
return false;
}
bool time24::operator<(time24 & t)
{
if(hours<t.hours &&
minutes<t.minutes &&
seconds<t.seconds)
return true;
else
return false;
}
main()
{
int h,m,s;
time24 t1(23,59,57);
time24 t2(22,23,23);
t1.get_time(h,m,s);
cout<<"t1 is"<<h<<":"<<m<<":"<<s<<endl;
t2.get_time(h,m,s);
cout<<"t2 is"<<h<<":"<<m<<":"<<s<<endl;
if(t1>t2)
cout<<"t1>t2"<<endl;
else if(t1<t2)
cout<<"t1<t2"<<endl;
else
cout<<"t1=t2"<<endl;
}
这个程序里面
void time24::set_time(int h,int m,int s)
{
hours=h;minutes=m;seconds=s;
}
说明用,没有看出来,这是教科书上写的
打错字了,应该是 什么用 展开
using namespace std;
class time24
{
public:
time24(int h=0,int m=0,int s=0);
void set_time(int h,int m,int s);
void get_time(int& h,int& m,int& s) const;
bool operator>(time24& t);
bool operator<(time24& t);
private:
int hours;
int minutes;
int seconds;
};
time24::time24(int h,int m,int s):
hours(h),minutes(m),seconds(s)
{}
void time24::set_time(int h,int m,int s)
{
hours=h;minutes=m;seconds=s;
}
void time24::get_time(int& h,int& m,int& s) const
{
h=hours;m=minutes;s=seconds;
}
bool time24::operator>(time24 & t)
{
if(hours>t.hours &&
minutes>t.minutes &&
seconds>t.seconds)
return true;
else
return false;
}
bool time24::operator<(time24 & t)
{
if(hours<t.hours &&
minutes<t.minutes &&
seconds<t.seconds)
return true;
else
return false;
}
main()
{
int h,m,s;
time24 t1(23,59,57);
time24 t2(22,23,23);
t1.get_time(h,m,s);
cout<<"t1 is"<<h<<":"<<m<<":"<<s<<endl;
t2.get_time(h,m,s);
cout<<"t2 is"<<h<<":"<<m<<":"<<s<<endl;
if(t1>t2)
cout<<"t1>t2"<<endl;
else if(t1<t2)
cout<<"t1<t2"<<endl;
else
cout<<"t1=t2"<<endl;
}
这个程序里面
void time24::set_time(int h,int m,int s)
{
hours=h;minutes=m;seconds=s;
}
说明用,没有看出来,这是教科书上写的
打错字了,应该是 什么用 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询