Code ''MyCounter''
#ifndef MYCOUNTER_HPP
#define MYCOUNTER_HPP
#include<iostream>
class MyCounter
{
protected:
unsigned counter;
unsigned max;
public:
unsigned getCounter() const { return counter; }
unsigned getMax() const { return max; }
void increment()
{
if(counter == max)
counter = 0;
else
counter ++;
}
void reset() { counter = 0; }
void set(unsigned value) { counter = value; }
void setMax(unsigned value)
{
max = value;
if(value > counter)
counter = counter % max;
}
MyCounter(): counter(0), max(0) {}
MyCounter(unsigned theCounter,
unsigned theMax): counter(theCounter), max(theMax)
{}
explicit MyCounter(unsigned theMax):
max(theMax), counter(0)
{}
MyCounter(const MyCounter& anotherCounter):
counter(anotherCounter.counter),
max(anotherCounter.max)
{}
~MyCounter()
{}
};