xlebpyshek

Laboratory work - 2 (all options)

Mar 13th, 2021 (edited)
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.98 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <utility>
  4. #include <map>
  5. #include <functional>
  6. #include "windows.h"
  7. using namespace std;
  8.  
  9. void staining(string text, int color) {
  10.     HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  11.     SetConsoleTextAttribute(hConsole, color);
  12.     cout << text << endl;
  13. }
  14.  
  15. void II() {
  16.     system("cls");
  17.     staining("Некорректный ввод!\nПопробуйте снова", 4);
  18.     Sleep(2000);
  19. }
  20.  
  21. static map<string, function<int(void)>> funcs = {
  22.  
  23.     {"func1",[]() {
  24.         return 1;
  25.     }},
  26.  
  27.     {"func2",[]() {
  28.         return 2;
  29.     }},
  30.  
  31.     {"func3",[]() {
  32.         return 3;
  33.     }},
  34.    
  35.     {"func4",[]() {
  36.         return 3;
  37.     }},
  38.    
  39.     {"func5",[]() {
  40.         return 3;
  41.     }},
  42.    
  43.     {"func6",[]() {
  44.         return 3;
  45.     }},
  46.    
  47.     {"func7",[]() {
  48.         return 3;
  49.     }},
  50.    
  51.     {"func8",[]() {
  52.         return 3;
  53.     }},
  54.    
  55.     {"func9",[]() {
  56.         return 3;
  57.     }},
  58.    
  59.     {"func10",[]() {
  60.         return 3;
  61.     }},
  62.    
  63.     {"func11",[]() {
  64.         return 3;
  65.     }},
  66.    
  67.     {"func12",[]() {
  68.         return 3;
  69.     }},
  70.    
  71.     {"func13",[]() {
  72.         return 3;
  73.     }},
  74.    
  75.     {"func14",[]() {
  76.         return 3;
  77.     }},
  78.    
  79.     {"func15",[]() {
  80.         return 3;
  81.     }},
  82.    
  83.     {"func16",[]() {
  84.         return 3;
  85.     }},
  86.    
  87.     {"func17",[]() {
  88.         return 3;
  89.     }}
  90.    
  91.     {"func18",[]() {
  92.         return 3;
  93.     }},
  94.    
  95.     {"func19",[]() {
  96.         return 3;
  97.     }},
  98.    
  99.     {"func20",[]() {
  100.         return 3;
  101.     }},
  102.    
  103.     {"func21",[]() {
  104.         return 3;
  105.     }},
  106.    
  107.     {"func22",[]() {
  108.         return 3;
  109.     }},
  110.    
  111.     {"func23",[]() {
  112.         return 3;
  113.     }},
  114.    
  115.     {"func24",[]() {
  116.         return 3;
  117.     }},
  118.    
  119.     {"func25
  120.        ",[]() {
  121.         return 3;
  122.     }}
  123. };
  124.  
  125.  
  126. int main() {
  127.     setlocale(0, "Russian");
  128.  
  129.     while (true) {
  130.         system("cls");
  131.         staining("Выберите вариант 1-25!", 3);
  132.         string option;
  133.         cin >> option;
  134.  
  135.  
  136.         size_t found = option.find_first_not_of("1234567890");
  137.         if (found == string::npos) {
  138.             if (stoi(option) > 0 && stoi(option) < 26) {
  139.                 cout << funcs["func" + option]() << endl;
  140.             }
  141.             else {
  142.                 II();
  143.             }
  144.         }
  145.         else {
  146.             II();
  147.         }
  148.     }
  149. }
Add Comment
Please, Sign In to add comment