改错3-38
#include<iostream.h>
class time
{
private:
int hour,minute,second;
public:
void settime(int h,int m,int s)
{
hour=(h>=0&&h<24)?h:0;
minute=(m>=0&&m<60)?m:0;
second=(s>=0&&s<60)?s:0;
}
void showtime()
{cout<<hour<<':'<<minute<<':'<<second<<endl;}
}
void main()
{
time t1;
t1.settime(14,52,66);
cout<<"The time is:";
t1.showtime();
return;
}
class time
{
private:
int hour,minute,second;
public:
void settime(int h,int m,int s)
{
hour=(h>=0&&h<24)?h:0;
minute=(m>=0&&m<60)?m:0;
second=(s>=0&&s<60)?s:0;
}
void showtime()
{
cout<<hour<<':'<<minute<<':'<<second<<endl;
}
};//加分號;
void main()
{
time t1;
t1.settime(14,52,66);
cout<<"The time is:";
t1.showtime();
}
class time
{
private:
int hour,minute,second;
public:
void settime(int,int,int);
void showtime();
};
void time::settime(int h,int m,int s)
{
hour=(h>=0&&h<24)?h:0;
minute=(m>=0&&m<60)?m:0;
second=(s>=0&&s<60)?s:0;
}
void time::showtime()
{
cout<<hour<<':'<<minute<<':'<<second<<endl;
}
void main()
{
time t1;
t1.settime(14,52,66);
cout<<"The time is:";
t1.showtime();
}
class time
{
private:
int hour,minute,second;
public:
void settime(int h,int m,int s)
{
hour=(h>=0&&h<24)?h:0;
minute=(m>=0&&m<60)?m:0;
second=(s>=0&&s<60)?s:0;
}
void showtime()
{cout<<hour<<':'<<minute<<':'<<second<<endl;}
}
void main()
{
time t1;
t1.settime(14,52,66);
cout<<"The time is:";
t1.showtime();
return;
}
?改后
View Code #include<iostream.h>class time
{
private:
int hour,minute,second;
public:
void settime(int h,int m,int s)
{
hour=(h>=0&&h<24)?h:0;
minute=(m>=0&&m<60)?m:0;
second=(s>=0&&s<60)?s:0;
}
void showtime()
{
cout<<hour<<':'<<minute<<':'<<second<<endl;
}
};//加分號;
void main()
{
time t1;
t1.settime(14,52,66);
cout<<"The time is:";
t1.showtime();
}
?改為外聯(lián)函數(shù):
View Code #include<iostream.h>class time
{
private:
int hour,minute,second;
public:
void settime(int,int,int);
void showtime();
};
void time::settime(int h,int m,int s)
{
hour=(h>=0&&h<24)?h:0;
minute=(m>=0&&m<60)?m:0;
second=(s>=0&&s<60)?s:0;
}
void time::showtime()
{
cout<<hour<<':'<<minute<<':'<<second<<endl;
}
void main()
{
time t1;
t1.settime(14,52,66);
cout<<"The time is:";
t1.showtime();
}
?
轉(zhuǎn)載于:https://www.cnblogs.com/galczn/archive/2012/03/28/2421706.html
總結(jié)
- 上一篇: Python GUI案例之看图猜成语开发
- 下一篇: Google Maps 地址转化成坐标