Start New Discussion within our Software Development Community
Implementation file

using namespace std;
#include "Interface.h"
#include <time.h>



void timer::start()
{
    if(! running)
    {
        begin=(unsigned int) clock();
        running=true;
    }
}

void timer::end()
{
    if(running)
    {
        finish=(unsigned int) clock();
        running=false;
    }
}

int timer::elapsed()
{
    if(running)
    {
        return((unsigned int) clock()-begin);
    }
    else
    {
        return finish-begin;
    }
}

int timer::output(unsigned int seconds)
{
    return seconds >= elapsed();
}




interface file
#ifndef INTERFACE_H_INCLUDED
#define INTERFACE_H_INCLUDED
//#include <time.h>
class timer
{
    public:
    void start();
    void end();
    int elapsed();
    int subtract();
    int add();
    int output(unsigned int seconds);
    private:
    bool running;
    int begin;
    int finish;
};
#endif // INTERFACE_H_INCLUDED


main file

#include <iostream>
using namespace std;
#include "Interface.h"
#include <conio.h>




    int main()
    {
        timer t;
        bool quit = false;
        char choice;
        choice=getch();
        while(! quit)
        {
            t.start();
            t.end();
            cout<<"the time difference is"<<t.elapsed();
        }
        return 0;
    }
Comments
he'
This question has already been answered. Start a new discussion instead.