Petro_zzz

26_10

Oct 26th, 2022
215
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.83 KB | None | 0 0
  1. #include <iostream>
  2. #include <ctime>
  3. #include <Windows.h> // полезное
  4.  
  5. using namespace std;
  6.  
  7. void digitsoperate();
  8.  
  9. int main(){
  10.     setlocale(LC_ALL, "rus");
  11.     digitsoperate();
  12. }
  13.  
  14. void digitsoperate() {
  15.     cout << endl;
  16.     cout << "Введите число и выберите, что необходимо определить." << endl;
  17.     int number;
  18.     cin >> number;
  19.     cout << endl;
  20.     Sleep(200);   // остановили выполнение на 200 мс
  21.     const int pause = 100;
  22.  
  23.     int curent_pos = 0;
  24.     bool is_notenter = true, is_keypressed = false, is_first = true;
  25.     do {
  26.         is_keypressed = false;
  27.         if (GetKeyState(VK_UP) & 0x8000) {  // такая проверка, если очнь хочется стрелочки использовать
  28.             Sleep(pause);
  29.             curent_pos--;
  30.             is_keypressed = true;
  31.         }
  32.         if (GetKeyState(VK_DOWN) & 0x8000) {
  33.             Sleep(pause);
  34.             curent_pos++;
  35.             is_keypressed = true;
  36.         }
  37.         if (GetKeyState(VK_RETURN) & 0x8000) {
  38.             Sleep(pause);
  39.             is_notenter = false;
  40.         }
  41.         if (GetKeyState(VK_ESCAPE) & 0x8000) {
  42.             Sleep(pause);
  43.             return;
  44.         }
  45.         if (is_first || is_keypressed) {
  46.             is_first = false;
  47.             curent_pos += (curent_pos < 0) ? 4 : 0;
  48.             curent_pos -= (curent_pos >= 4) ? 4 : 0;
  49.             system("cls");  // чистим консоль
  50.             cout << endl;
  51.             cout << "Введите число и выберите что необходимо определить." << endl;
  52.             cout << number << endl << endl;
  53.             switch (curent_pos) {
  54.             case 0:
  55.                 cout << " > Количество цифр в числе" << endl;
  56.                 cout << "   Сумма цифр в числе" << endl;
  57.                 cout << "   Cреднее арифметическое цифр" << endl;
  58.                 cout << "   Количество нулей в числе" << endl;
  59.                 break;
  60.             case 1:
  61.                 cout << "   Количество цифр в числе" << endl;
  62.                 cout << " > Сумма цифр в числе" << endl;
  63.                 cout << "   Cреднее арифметическое цифр" << endl;
  64.                 cout << "   Количество нулей в числе" << endl;
  65.                 break;
  66.             case 2:
  67.                 cout << "   Количество цифр в числе" << endl;
  68.                 cout << "   Сумма цифр в числе" << endl;
  69.                 cout << " > Cреднее арифметическое цифр" << endl;
  70.                 cout << "   Количество нулей в числе" << endl;
  71.                 break;
  72.             case 3:
  73.                 cout << "   Количество цифр в числе" << endl;
  74.                 cout << "   Сумма цифр в числе" << endl;
  75.                 cout << "   Cреднее арифметическое цифр" << endl;
  76.                 cout << " > Количество нулей в числе" << endl;
  77.             }
  78.         }
  79.     } while (is_notenter);
  80.  
  81.     int res = 0, count = 0;
  82.     cout << endl;
  83.     switch (curent_pos) {
  84.     case 0:
  85.         do {
  86.             number /= 10;
  87.             count++;
  88.         } while (number);
  89.         res = count;
  90.         cout << "Количество цифр в числе равно " << res << endl;
  91.         break;
  92.     case 1:
  93.         do {
  94.             res += number % 10;
  95.             number /= 10;
  96.         } while (number);
  97.         cout << "Сумма цифр в числе равно " << res << endl;
  98.         break;
  99.     case 2:
  100.         do {
  101.             res += number % 10;
  102.             number /= 10;
  103.             count++;
  104.         } while (number);
  105.         if (count > 0)
  106.             cout << "Cреднее арифметическое цифр равно" << double(res) / count << endl;
  107.         else
  108.             cout << "Внимание! Цифр нет." << endl;
  109.         break;
  110.     case 3:
  111.         do {
  112.             if (number % 10 == 0)
  113.                 count++;
  114.             number /= 10;
  115.         } while (number);
  116.         res = count;
  117.         cout << "Количество нулей в числе равно " << res << endl;
  118.         break;
  119.     }
  120.  
  121.     Sleep(500);
  122.     cout << "Введите 0 и нажмите Enter чтобы выйти.";
  123.     cin >> number;
  124. }
  125.  
  126. void cheesswood(){
  127.     cout << endl;
  128.     cout << "Введите  размер клетки (от 1 до 8)" << endl;
  129.     int sz;
  130.     const int numcell = 8;
  131.     cin >> sz;
  132.     cout << endl << endl;
  133.     int ex1, ex2;
  134.  
  135.     cout << "       ";
  136.     for (int k = 0; k < numcell*sz; k++)
  137.         if (k % sz == sz / 2)
  138.             cout << char(int('A')+k/sz);
  139.         else
  140.             cout << " ";
  141.     cout << endl;
  142.  
  143.     cout << "      +";
  144.     for (int k = 0; k < numcell * sz; k++)
  145.         cout << "-";
  146.  
  147.     cout << "+" << endl;
  148.     for (int k = 0; k < numcell * sz; k++) {
  149.         if(k % sz == sz / 2)
  150.             cout << "     "<< k/sz+1 <<"|";
  151.         else
  152.             cout << "      |";
  153.         for (int n = 0; n < numcell * sz; n++) {
  154.             ex1 = ((k / sz) % 2) ? 1 : -1;
  155.             ex2 = ((n / sz) % 2) ? 1 : -1;
  156.             cout << ((ex1 * ex2 > 0) ? "*" : " "); // This is XOR
  157.         }
  158.         cout << "|";
  159.         if (k % sz == sz / 2)
  160.             cout <<k / sz + 1;
  161.         cout << endl;
  162.     }
  163.     cout << "      +";
  164.     for (int k = 0; k < numcell * sz; k++)
  165.         cout << "-";
  166.     cout << "+" << endl;
  167.  
  168.     cout << "       ";
  169.     for (int k = 0; k < numcell * sz; k++)
  170.         if (k % sz == sz / 2)
  171.             cout << char(int('A') + k / sz);
  172.         else
  173.             cout << " ";
  174.     cout << endl;
  175. }
Advertisement
Add Comment
Please, Sign In to add comment