#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;
}

 改后

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();
}

 改为外联函数:

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();
}

 

posted on 2012-03-28 18:02  C's  阅读(186)  评论(0)    收藏  举报