采用运算符重载实现时钟类计时程序 ,这里是本人编写的一个程序,错误多多,该如何修改呢?
#include<iostream>using namespace std;
class Time
{
int h,m,s;
public:
Time(int a=0,int b=0,int c=0)
{
h=a;
m=b;
s=c;
}
void show()
{
cout<<h<<":"<<m<<":"<<s<<endl;
}
Time::operator++();
Time::operator++(int);
};
Time::operator++()
{
++s;
if(s>=60)
{
s=s-60;
++m;
if(m>=60)
{
m=m-60;
++h;
h=h%24;
}
}
}
int main()
{
Time c1(23,59,59),c2;
c2=++c1;
c2.show();
return 0;
}
[ 本帖最后由 yangxiaoniu 于 2014-11-12 23:07 编辑 ]