满意答案
iwyxg
2013.11.09
采纳率:50% 等级:10
已帮助:919人
#include
#include
using namespace std;class Time {
private:
int h;
int m;
int s;public:
Time();
Time(int h, int m, int s);
~Time(){
cout<
}
void show();
void tick();
void run();
};Time::Time() {
h = 0;
m = 0;
s = 2;
}Time::Time(int h, int m, int s) {
this->h = h;
this->m = m;
this->s = s;
}void Time::show() {
cout << h << ":" << m << ":" << s << endl;
fflush(stdout);
}void Time::tick() {
Sleep(1000);
if (--this->s < 0) {
this->s = 59;
if (--this->m < 0) {
this->m = 59;
if (--this->h < 0)
this->m = 0;
}
}
}void Time::run() {
while (this->h > 0 || this->m > 0 || this->s > 0) {
show();
tick();
}}int main() {
Time t(11, 20, 5);
t.run();
return 0;
}
00分享举报