秒表(mtime)

· · 个人记录

link

秒表

#include<iostream>
#include<iomanip>
#include <windows.h>
using  namespace  std;
class CLOCK
{
private:
    int hour;
    int minute;
    int second;
public:
    CLOCK(int newh=0,int newm=0, int news=0);
    ~CLOCK();
    void init(int newh,int newm, int news);
    void run();
};

CLOCK::CLOCK(int newh,int newm, int news)
{
    hour=newh;
    minute=newm;
    second=news;
}
void CLOCK::init(int newh,int newm, int news)
{
    hour=newh;
    minute=newm;
    second=news;
}
void CLOCK::run()
{
    while(1)
    {
        system("cls");
        cout<<setw(2)<<setfill('0')<<hour<<":";
        cout<<setw(2)<<setfill('0')<<minute<<":";
        cout<<setw(2)<<setfill('0')<<second;
        Sleep(1000);
        if(++second==60)
        {
            second=0;
            minute=minute+1;
            if(minute==60)
            {
                minute=0;
                hour=hour+1;
                if(hour==24)
                {
                    hour=0;
                }
            }
        }
    }
}
CLOCK::~CLOCK()
{
}
int main()
{
    CLOCK c;
    c.init(0,0,0);
    c.run();
    system("pause");
    return 0;

}