/
VadyaS
/
structRW2
Обзор
Документация
Войти
/
VadyaS
/
structRW2
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
2counterRW3.cpp
78 строк
1019 B
VadyaS
upload files
06 май 2025, 08:58
06 май 2025, 08:58
bac5788
Код
Авторство
О чём код?
#include<iostream> #include<string> class Counter { private: int num{}; public: Counter(int num) : num(num) {} Counter() : num(1) {} void substract() { num--; } void add() { num++; } int getNum() { return num; } }; int main() { std::string answer{}; int num{}; char ch{}; Counter c1; std::cout << "Do you want to specify the initial value of the counter? Enter yes or no: "; std::cin >> answer; if (answer == "yes") { std::cout << "Enter the initial value of the counter: "; std::cin >> num; c1 = Counter(num); } while (true) { std::cout << "Enter the command('+', '-', '=' or 'x') : "; std::cin >> ch; if (ch == '+') { c1.add(); } else if (ch == '-') { c1.substract(); } else if (ch == '=') { std::cout << c1.getNum() << std::endl; } else if (ch == 'x') { std::cout << "Good bye"; break; } else { std::cout << "incorrect command "; } } }