/
VadyaS
/
classes
Обзор
Документация
Войти
/
VadyaS
/
classes
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
counter2.cpp
86 строк
1 KB
VadyaS
upload files
02 май 2025, 16:51
02 май 2025, 16:51
022f7c9
Код
Авторство
О чём код?
#include<iostream> class Counter { private: std::string answer{}; int num{}; char ch{}; public: Counter() { 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; this->num = num; } else if(answer=="no") { num = 1; std::cout << "counter = " << this->num << std::endl; } else { std::cout<<"error"<<std::endl; } } void f() { std::cout << "Enter the command ('+', '-', '=' or 'x'):"; std::cin >> ch; add(); substract(); summ(); } public: void add() { if (ch == '+') { ++num; } } void substract() { if (ch == '-') { --num; } } void summ() { if (ch == '=') { std::cout << num<<std::endl; } } bool close() { if (ch == 'x') { std::cout << "God bye " << std::endl; return false; } else { return true; } } }; int main() { Counter counter; while (counter.close()) { counter.f(); } }