Develop

[c++] p.58 연습문제 2번

by hooni posted Apr 23, 2003
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄
#include<iostream.h>
#include<time.h>
#include<string.h>

class stopwatch{
        clock_t c_start, c_end, st, k;
    public :
        stopwatch();
        ~stopwatch();
        start();
        stop(int i);
        show();
};

stopwatch::stopwatch(){
}

stopwatch::~stopwatch(){
        c_end = clock();
        cout << "Bye~ : " << (int)( (c_end - c_start)/CLK_TCK ) << " secn";
}

stopwatch::show(){
        c_end = clock();
        cout << "Show time : " << (int)( (c_end - c_start)/CLK_TCK ) << " secn";
}

stopwatch::start(){
        c_start = clock();
}

stopwatch::stop(int i){
        if(i==0){
                k = clock();
        }else if(i==1){
                st = clock();
                st = st - k;
                c_start = c_start + st;
        }
}

int main(){
        char com[10];
        stopwatch ob;

        cout << "Command: start, stop, exit n";

        while(1){
                cin >> com;
                if(!strcmp(com, "start")) ob.start();
                if(!strcmp(com, "stop")){
                        ob.stop(0);
                        cin >> com;
                        ob.stop(1);
                }if(!strcmp(com, "show")) ob.show();
                if(!strcmp(com, "exit")) return 0;
        }