PhotoShaman

Laba1

Nov 19th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 7.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3. #include <cmath>
  4. #include <windows.h>
  5. #pragma hdrstop
  6.  
  7. using namespace std;
  8.  
  9. static void SetCursorPosition(int x, int y)
  10. {
  11.     COORD coord;
  12.     coord.X = x;
  13.     coord.Y = y;
  14.     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  15. }
  16. enum ConsoleColor
  17. {
  18.     Black = 0,
  19.     Blue = 1,
  20.     Green = 2,
  21.     Cyan = 3,
  22.     Red = 4,
  23.     Magenta = 5,
  24.     Brown = 6,
  25.     LightGray = 7,
  26.     DarkGray = 8,
  27.     LightBlue = 9,
  28.     LightGreen = 10,
  29.     LightCyan = 11,
  30.     LightRed = 12,
  31.     LightMagenta = 13,
  32.     Yellow = 14,
  33.     White = 15
  34. };
  35. static void SetColor(int text, int background) // устанавливает цвет текста и фона в консоли
  36. {
  37.     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  38.     SetConsoleTextAttribute(hStdOut, (WORD)((background << 4) | text));
  39. }
  40. static void SetColor(int text, ConsoleColor/*int*/ background) // устанавливает цвет текста и фона в консоли
  41. {
  42.     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  43.     SetConsoleTextAttribute(hStdOut, (WORD)((background << 4) | text));
  44. }
  45. static void CursorVisible(bool visible)
  46. {
  47.     void* handle = GetStdHandle(STD_OUTPUT_HANDLE);
  48.     CONSOLE_CURSOR_INFO structCursorInfo;
  49.     GetConsoleCursorInfo(handle, &structCursorInfo);
  50.     structCursorInfo.bVisible = visible;
  51.     SetConsoleCursorInfo(handle, &structCursorInfo);
  52. }
  53.  
  54. static void ASCIILogo()
  55. {
  56.     SetColor(2, 0);
  57.     for (int i = 3; i < 9; i += 2)
  58.     {
  59.         SetCursorPosition(0, i); cout << "-------------------------------";
  60.         SetCursorPosition(69, i); cout << "-------------------------------";
  61.     }
  62.     SetCursorPosition(0, 1); for (int i = 0; i < 99; i++) cout << '-';
  63.     SetCursorPosition(0, 9); for (int i = 0; i < 99; i++) cout << '-';
  64.     SetColor(15, 0);
  65.     SetCursorPosition(29, 3); cout << "88      8888    888888      8888      88";
  66.     SetCursorPosition(29, 4); cout << "88     88  88   88    88   88  88    888";
  67.     SetCursorPosition(29, 5); cout << "88     88  88   888888     88  88   8888";
  68.     SetCursorPosition(29, 6); cout << "88     888888   88    88   888888     88";
  69.     SetCursorPosition(29, 7); cout << "88     88  88   88    88   88  88     88";
  70.     SetCursorPosition(29, 8); cout << "8888   88  88   888888     88  88     88";
  71. }
  72. static void Task1()
  73. {
  74.     double alpha, beta, z1, z2;
  75.  
  76.     cout << "Введите угол альфа: ";
  77.     cin >> alpha;
  78.     alpha *= 3.1416 / 180;
  79.  
  80.     cout << "Введите угол бета:  ";
  81.     cin >> beta;
  82.     beta *= 3.1416 / 180;
  83.  
  84.     z1 = pow(cos(alpha) - cos(beta), 2) - pow(sin(alpha) - sin(beta), 2);
  85.     cout << "z1 = " << z1 << endl;
  86.  
  87.     z2 = -4 * pow(sin((alpha - beta) / 2), 2) * cos(alpha + beta);
  88.     cout << "z2 = " << z2 << endl;
  89.     system("pause"); //Delay
  90. }
  91. static void Task2()
  92. {
  93.     double usd, eur, count, usdPrice, eurPrice;
  94.  
  95.     cout << "Введите курс USD: ";
  96.     cin >> usdPrice;
  97.  
  98.     cout << "Введите курс EUR: ";
  99.     cin >> eurPrice;
  100.  
  101.     cout << "Введите количество гривен: ";
  102.     cin >> count;
  103.  
  104.     usd = count / usdPrice;
  105.     eur = count / eurPrice;
  106.  
  107.     cout << endl << "Гривна - Доллар: " << count << " <-> " << usd << endl;
  108.     cout << "Гривна - Евро:   " << count << " <-> " << eur << endl;
  109.     system("pause"); //Delay
  110. }
  111. static void Task3()
  112. {
  113.     int startHour, startMin, startSec, endHour, endMin, endSec, timeSum, hour, min, sec;
  114.  
  115.     cout << "Введите начальное значение времени в формате (часы) (минуты) (секунды)\n";
  116.     cin >> startHour >> startMin >> startSec;
  117.  
  118.     if (startHour < 0 || startHour > 23 || startMin < 0 || startMin > 59 || startSec < 0 || startSec > 59)
  119.         cout << "Ошибка!!1!" << endl;
  120.     else
  121.     {
  122.         cout << "Введите конечное значение времени\n";
  123.         cin >> endHour >> endMin >> endSec;
  124.  
  125.         if (endHour < 0 || endHour > 23 || endMin < 0 || endMin > 59 || endSec < 0 || endSec > 59)
  126.             cout << "Ошибка!!1!" << endl;
  127.         else
  128.         {
  129.             timeSum = (endHour - startHour) * 3600 + (endMin - startMin) * 60 + (endSec - startSec);
  130.             hour = (timeSum / 3600);
  131.             min = (timeSum % 3600) / 60;
  132.             sec = ((timeSum % 3600) % 60);
  133.             cout << hour << ' ' << min << ' ' << sec << endl;
  134.         }
  135.     }
  136.     system("pause"); //Delay
  137. }
  138. static void Task4()
  139. {
  140.     double number1, number2, percent;
  141.  
  142.     cout << "Введите первое число: ";
  143.     cin >> number1;
  144.  
  145.     cout << "Введите второе число: ";
  146.     cin >> number2;
  147.  
  148.     percent = number1 / number2 * 100;
  149.     cout << "Процентная часть первого числа от второго: " << percent << endl;
  150.     system("pause"); //Delay
  151. }
  152. static void TaskList()
  153. {
  154.     SetColor(15, 0);
  155.     SetCursorPosition(29, 12); cout << "Основное задание:";
  156.     SetCursorPosition(56, 12); cout << "Вариант 9";
  157.     SetColor(11, 0);
  158.     SetCursorPosition(29, 13); cout << "Дополнительные задания:";
  159.     SetCursorPosition(56, 13); cout << "Задание 1";
  160.     SetCursorPosition(56, 14); cout << "Задание 2";
  161.     SetCursorPosition(56, 15); cout << "Задание 3";
  162.     SetCursorPosition(29, 46); cout << "Управление:";
  163.     SetCursorPosition(40, 47); cout << "Движение курсора стрелочками вверх и вниз";
  164.     SetCursorPosition(40, 48); cout << "Выбор задания - стрелочка влево";
  165.     SetCursorPosition(40, 49); cout << "Выход - ESC";
  166. }
  167. static void ChooseTask()
  168. {
  169.     int y = 12;
  170.     CursorVisible(false);
  171.     SetColor(12, 0);
  172.     while (true)
  173.     {
  174.         SetCursorPosition(65, y); cout << "<===";
  175.         if (GetAsyncKeyState(VK_UP))
  176.             if (y != 12)
  177.             {
  178.                 SetCursorPosition(65, y); cout << "    ";
  179.                 y -= 1;
  180.             }
  181.         if (GetAsyncKeyState(VK_DOWN))
  182.             if (y != 15)
  183.             {
  184.                 SetCursorPosition(65, y); cout << "    ";
  185.                 y += 1;
  186.             }
  187.         if (GetAsyncKeyState(VK_LEFT))
  188.         {
  189.             system("cls");
  190.             SetColor(15, 0);
  191.             CursorVisible(true);
  192.             switch (y)
  193.             {
  194.             case 12: Task1();
  195.                 break;
  196.             case 13: Task2();
  197.                 break;
  198.             case 14: Task3();
  199.                 break;
  200.             case 15: Task4();
  201.                 break;
  202.             }
  203.             Sleep(1000);
  204.             system("cls");
  205.             return;
  206.         }
  207.         if (GetAsyncKeyState(VK_ESCAPE)) exit(1);
  208.         Sleep(200);
  209.     }
  210. }
  211. void main()
  212. {
  213.     setlocale(LC_ALL, "Russian");
  214.     system("mode con cols=100 lines=50");
  215.     SetConsoleTitle("Laba 1"); //если ошибка, заменить на: system("title Laba 1");
  216.     while (true)
  217.     {
  218.         ASCIILogo();
  219.         TaskList();
  220.         ChooseTask();
  221.     }
  222. }
Advertisement
Add Comment
Please, Sign In to add comment