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;
}
lotrsimp12345 37 Posting Pro in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.