abubaca

Untitled

Dec 22nd, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. #include <iostream>
  2. #include "windows.h"
  3. #include <vector>
  4. #include <string>
  5. #include <conio.h>
  6.  
  7. using namespace std;
  8.  
  9. HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE);
  10. #define WIDTH 80
  11. #define HEIGHT 30
  12.  
  13. void MainGet();
  14.  
  15. int main()
  16. {
  17.     string resize = "mode "+ to_string(WIDTH)+ ", "+ to_string(HEIGHT);
  18.     system(resize.c_str());
  19.     MainGet();
  20. }
  21.  
  22. void print(const char text[], int x, int y)
  23. {
  24.     COORD pos;
  25.     pos.X = x;
  26.     pos.Y = y;
  27.     SetConsoleCursorPosition(hCon, pos);
  28.     cout << text;
  29. }
  30.  
  31. void MenuShow(int nomber)
  32. {
  33.     vector <string> points = {"sin", "cos", "simple function"};
  34.     system("cls");
  35.     int xMiddle = WIDTH / 2;
  36.     int yPart = HEIGHT / (points.size() + 1);
  37.     for (int i = 1; i <= points.size(); i++)
  38.     {
  39.         if (i == nomber)
  40.         {
  41.             string temp = "<<" + points[i - 1] + ">>";
  42.             print(temp.c_str(), xMiddle - temp.length() / 2, yPart*i);
  43.         }
  44.         else
  45.             print(points[i-1].c_str(), xMiddle - points[i - 1].length() / 2, yPart*i);
  46.     }
  47. }
  48.  
  49. void MainGet()
  50. {
  51.     int mode = 0; // 0 - menu, 1 - count get
  52.     int menu_point = 1;
  53.     MenuShow(menu_point);
  54.     while (true)
  55.     {
  56.         int choice = _getch();
  57.         if (!mode)
  58.         {
  59.             switch (choice)
  60.             {
  61.             case 72:
  62.                 menu_point = menu_point == 1 ? menu_point = 3 : menu_point - 1;
  63.                 break;
  64.             case 80:
  65.                 menu_point = menu_point == 3 ? menu_point = 1 : menu_point + 1;
  66.                 break;
  67.             }
  68.             MenuShow(menu_point);
  69.         }
  70.         else
  71.         {
  72.  
  73.         }
  74.     }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment