// Jan 29 2006 by Dustin McCormick < djmccormick@gmail.com > // Tested with gcc version 3.3.4 on GNU/Linux 2.4.29 i686 // // gcc: http://gcc.gnu.org/ // GNU: http://www.gnu.org/ // Linux: http://www.kernel.org/ #include using namespace std; class Counter{ public: Counter(int size); Counter(); void reset(); void incr1(short int x=1); void incr10(short int x=1); void incr100(short int x=1); void incr1000(short int x=1); bool overflow(); private: int countLimit; int countCurrent; }; int main(){ int size; cout << "Welcome to the counter program.\n" << endl; cout << "Please enter the maximum value that this counter will hold: "; cin >> size; cout << endl; return 0; } Counter::Counter(int size) : countLimit(size){ } Counter::Counter() : countLimit(9999){ } void Counter::reset() : countCurrent(0){ } void Counter::incr1(short int x){ if(x > 9 || x < 0){ cout << "ERROR: Illegal argument @ Counter::incr1(x)" << endl; } else{ countCurrent += (x*1); } } void Counter::incr10(short int x){ if(x > 9 || x < 0){ cout << "ERROR: Illegal argument @ Counter::incr1(x)" << endl; } else{ countCurrent += (x*10); } } void Counter::incr100(short int x){ if(x > 9 || x < 0){ cout << "ERROR: Illegal argument @ Counter::incr1(x)" << endl; } else{ countCurrent += (x*100); } } void Counter::incr1000(short int x){ if(x > 9 || x < 0){ cout << "ERROR: Illegal argument @ Counter::incr1(x)" << endl; } else{ countCurrent += (x*1000); } } bool Counter::overflow(){ if(countCurrent > countLimit){ return true; } else{ return false; } }