Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <ctime>
- #include <Windows.h> // полезное
- using namespace std;
- void digitsoperate();
- int main(){
- setlocale(LC_ALL, "rus");
- digitsoperate();
- }
- void digitsoperate() {
- cout << endl;
- cout << "Введите число и выберите, что необходимо определить." << endl;
- int number;
- cin >> number;
- cout << endl;
- Sleep(200); // остановили выполнение на 200 мс
- const int pause = 100;
- int curent_pos = 0;
- bool is_notenter = true, is_keypressed = false, is_first = true;
- do {
- is_keypressed = false;
- if (GetKeyState(VK_UP) & 0x8000) { // такая проверка, если очнь хочется стрелочки использовать
- Sleep(pause);
- curent_pos--;
- is_keypressed = true;
- }
- if (GetKeyState(VK_DOWN) & 0x8000) {
- Sleep(pause);
- curent_pos++;
- is_keypressed = true;
- }
- if (GetKeyState(VK_RETURN) & 0x8000) {
- Sleep(pause);
- is_notenter = false;
- }
- if (GetKeyState(VK_ESCAPE) & 0x8000) {
- Sleep(pause);
- return;
- }
- if (is_first || is_keypressed) {
- is_first = false;
- curent_pos += (curent_pos < 0) ? 4 : 0;
- curent_pos -= (curent_pos >= 4) ? 4 : 0;
- system("cls"); // чистим консоль
- cout << endl;
- cout << "Введите число и выберите что необходимо определить." << endl;
- cout << number << endl << endl;
- switch (curent_pos) {
- case 0:
- cout << " > Количество цифр в числе" << endl;
- cout << " Сумма цифр в числе" << endl;
- cout << " Cреднее арифметическое цифр" << endl;
- cout << " Количество нулей в числе" << endl;
- break;
- case 1:
- cout << " Количество цифр в числе" << endl;
- cout << " > Сумма цифр в числе" << endl;
- cout << " Cреднее арифметическое цифр" << endl;
- cout << " Количество нулей в числе" << endl;
- break;
- case 2:
- cout << " Количество цифр в числе" << endl;
- cout << " Сумма цифр в числе" << endl;
- cout << " > Cреднее арифметическое цифр" << endl;
- cout << " Количество нулей в числе" << endl;
- break;
- case 3:
- cout << " Количество цифр в числе" << endl;
- cout << " Сумма цифр в числе" << endl;
- cout << " Cреднее арифметическое цифр" << endl;
- cout << " > Количество нулей в числе" << endl;
- }
- }
- } while (is_notenter);
- int res = 0, count = 0;
- cout << endl;
- switch (curent_pos) {
- case 0:
- do {
- number /= 10;
- count++;
- } while (number);
- res = count;
- cout << "Количество цифр в числе равно " << res << endl;
- break;
- case 1:
- do {
- res += number % 10;
- number /= 10;
- } while (number);
- cout << "Сумма цифр в числе равно " << res << endl;
- break;
- case 2:
- do {
- res += number % 10;
- number /= 10;
- count++;
- } while (number);
- if (count > 0)
- cout << "Cреднее арифметическое цифр равно" << double(res) / count << endl;
- else
- cout << "Внимание! Цифр нет." << endl;
- break;
- case 3:
- do {
- if (number % 10 == 0)
- count++;
- number /= 10;
- } while (number);
- res = count;
- cout << "Количество нулей в числе равно " << res << endl;
- break;
- }
- Sleep(500);
- cout << "Введите 0 и нажмите Enter чтобы выйти.";
- cin >> number;
- }
- void cheesswood(){
- cout << endl;
- cout << "Введите размер клетки (от 1 до 8)" << endl;
- int sz;
- const int numcell = 8;
- cin >> sz;
- cout << endl << endl;
- int ex1, ex2;
- cout << " ";
- for (int k = 0; k < numcell*sz; k++)
- if (k % sz == sz / 2)
- cout << char(int('A')+k/sz);
- else
- cout << " ";
- cout << endl;
- cout << " +";
- for (int k = 0; k < numcell * sz; k++)
- cout << "-";
- cout << "+" << endl;
- for (int k = 0; k < numcell * sz; k++) {
- if(k % sz == sz / 2)
- cout << " "<< k/sz+1 <<"|";
- else
- cout << " |";
- for (int n = 0; n < numcell * sz; n++) {
- ex1 = ((k / sz) % 2) ? 1 : -1;
- ex2 = ((n / sz) % 2) ? 1 : -1;
- cout << ((ex1 * ex2 > 0) ? "*" : " "); // This is XOR
- }
- cout << "|";
- if (k % sz == sz / 2)
- cout <<k / sz + 1;
- cout << endl;
- }
- cout << " +";
- for (int k = 0; k < numcell * sz; k++)
- cout << "-";
- cout << "+" << endl;
- cout << " ";
- for (int k = 0; k < numcell * sz; k++)
- if (k % sz == sz / 2)
- cout << char(int('A') + k / sz);
- else
- cout << " ";
- cout << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment