Untitled
unknown
c_cpp
a year ago
1.2 kB
2
Indexable
Never
#include <iostream> #include <windows.h> using namespace std; class cCounter { public: cCounter(int _v) : counter(_v) { if((_v < 0) || (_v > 999)) std::cout << "Wrong number\n"; } cCounter() { this->counter = 0; } void add() { counter++; if(counter > 999) counter = 0; } void reset() { counter = 0; } int get() { return counter; } private: int counter; }; int main() { SetConsoleCP(1251); SetConsoleOutputCP(1251); setlocale(0, ""); int n; cout << "Enter the meter reading : "; cin >> n; cCounter counter(n); while(true) { char opt; cout << "Enter +, c, 1 or e to exit: "; cin >> opt; switch(opt) { case '+': counter.add(); break; case 'c': counter.reset(); break; case '1': cout << "meter readings " << counter.get() << "\n"; break; case 'e': return 0; default: cout << "Incorrect character!\n"; } } return 0; }