//file cirnum.hpp
#ifndef CIRNUM_H
#define CIRNUM_H
class CIR_NUMS
{
public:
CIR_NUMS(int min,int max,int value);
~CIR_NUMS();
void set_mode(int min,int max);
void set_value(int value);
int get_value();
void increment();
void decrement();
private:
int min_val;
int max_val;
int current;
};
#endif
//file cirnum.cpp
#include "cir_nums.h"
#include<iostream.h>
CIR_NUMS::CIR_NUMS(int min ,int max,int value)
{ min_val=(min<=max)?min:max;
max_val=(min<=max)?max:min;
if(value>=min_val&&value<=max_val)
current=value;
else
cout<<"Current value is not valid!"
<<endl;
return;
}
CIR_NUMS::~CIR_NUMS()
{
return;
}
void CIR_NUMS::set_mode(int min,int max)
{ min_val=(min<=max)?min:max;
max_val=(min<=max)?max:min;
return;
}
void CIR_NUMS::set_value(int value)
{ if(value>=min_val&¤t<=max_val)
current=value;
else
cout<<"current value is not valid!"
<< endl;
return ;
}
int CIR_NUMS::get_value()
{ return (current);
}
void CIR_NUMS::increment()
{ int mode=max_val-min_val+1;
current=((current-min_val)+1)%mode+min_val;
return;
}
void CIR_NUMS::decrement()
{ int mode=max_val-min_val;
current=((current-min_val)-1+mode)%mode+min_val;
return;
}