// file count.h #include class counter { public: counter(void); counter(int); void count(void); void unCount(void); int counterIs(void); void setCounter(int); private: int counterValue; }; // file count.cpp #include "count.h" counter::counter(void) { counterValue = 0; } counter::counter(int initV) { counterValue = initV; } void counter::count(void) { counterValue ++; } void counter::unCount(void) { counterValue --; } int counter::counterIs(void) { return counterValue; } void counter::setCounter(int value) { counterValue = value; } // file testCount.cpp #include "count.h" void main(void) { counter a, b(2); cout << " value of counter a should be 0\n"; cout << " value of counter a is " << a.counterIs() << endl; cout << " value of counter b should be 2\n"; cout << " value of counter b is " << b.counterIs() << endl; cout << " now we increse the counter a by 2 ... \n"; a.count(); // one a.count(); // two cout << " now we increse the counter b by 2 ... \n"; b.count(); // one b.count(); // two cout << " now the value of counter a should be 2 and b should be 4\n"; cout << " a is " << a.counterIs() << " b is " << b.counterIs() << endl; cout << " set counter a as -1 b as 0\n"; a.setCounter(-1); b.setCounter(0); cout << " a value is " << a.counterIs() << " b value is " << b.counterIs() << endl; cout << " test finished... \n"; }