Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- #include <cmath>
- #include <windows.h>
- #pragma hdrstop
- using namespace std;
- static void SetCursorPosition(int x, int y)
- {
- COORD coord;
- coord.X = x;
- coord.Y = y;
- SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
- }
- enum ConsoleColor
- {
- Black = 0,
- Blue = 1,
- Green = 2,
- Cyan = 3,
- Red = 4,
- Magenta = 5,
- Brown = 6,
- LightGray = 7,
- DarkGray = 8,
- LightBlue = 9,
- LightGreen = 10,
- LightCyan = 11,
- LightRed = 12,
- LightMagenta = 13,
- Yellow = 14,
- White = 15
- };
- static void SetColor(int text, int background) // устанавливает цвет текста и фона в консоли
- {
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hStdOut, (WORD)((background << 4) | text));
- }
- static void SetColor(int text, ConsoleColor/*int*/ background) // устанавливает цвет текста и фона в консоли
- {
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hStdOut, (WORD)((background << 4) | text));
- }
- static void CursorVisible(bool visible)
- {
- void* handle = GetStdHandle(STD_OUTPUT_HANDLE);
- CONSOLE_CURSOR_INFO structCursorInfo;
- GetConsoleCursorInfo(handle, &structCursorInfo);
- structCursorInfo.bVisible = visible;
- SetConsoleCursorInfo(handle, &structCursorInfo);
- }
- static void ASCIILogo()
- {
- SetColor(2, 0);
- for (int i = 3; i < 9; i += 2)
- {
- SetCursorPosition(0, i); cout << "-------------------------------";
- SetCursorPosition(69, i); cout << "-------------------------------";
- }
- SetCursorPosition(0, 1); for (int i = 0; i < 99; i++) cout << '-';
- SetCursorPosition(0, 9); for (int i = 0; i < 99; i++) cout << '-';
- SetColor(15, 0);
- SetCursorPosition(29, 3); cout << "88 8888 888888 8888 88";
- SetCursorPosition(29, 4); cout << "88 88 88 88 88 88 88 888";
- SetCursorPosition(29, 5); cout << "88 88 88 888888 88 88 8888";
- SetCursorPosition(29, 6); cout << "88 888888 88 88 888888 88";
- SetCursorPosition(29, 7); cout << "88 88 88 88 88 88 88 88";
- SetCursorPosition(29, 8); cout << "8888 88 88 888888 88 88 88";
- }
- static void Task1()
- {
- double alpha, beta, z1, z2;
- cout << "Введите угол альфа: ";
- cin >> alpha;
- alpha *= 3.1416 / 180;
- cout << "Введите угол бета: ";
- cin >> beta;
- beta *= 3.1416 / 180;
- z1 = pow(cos(alpha) - cos(beta), 2) - pow(sin(alpha) - sin(beta), 2);
- cout << "z1 = " << z1 << endl;
- z2 = -4 * pow(sin((alpha - beta) / 2), 2) * cos(alpha + beta);
- cout << "z2 = " << z2 << endl;
- system("pause"); //Delay
- }
- static void Task2()
- {
- double usd, eur, count, usdPrice, eurPrice;
- cout << "Введите курс USD: ";
- cin >> usdPrice;
- cout << "Введите курс EUR: ";
- cin >> eurPrice;
- cout << "Введите количество гривен: ";
- cin >> count;
- usd = count / usdPrice;
- eur = count / eurPrice;
- cout << endl << "Гривна - Доллар: " << count << " <-> " << usd << endl;
- cout << "Гривна - Евро: " << count << " <-> " << eur << endl;
- system("pause"); //Delay
- }
- static void Task3()
- {
- int startHour, startMin, startSec, endHour, endMin, endSec, timeSum, hour, min, sec;
- cout << "Введите начальное значение времени в формате (часы) (минуты) (секунды)\n";
- cin >> startHour >> startMin >> startSec;
- if (startHour < 0 || startHour > 23 || startMin < 0 || startMin > 59 || startSec < 0 || startSec > 59)
- cout << "Ошибка!!1!" << endl;
- else
- {
- cout << "Введите конечное значение времени\n";
- cin >> endHour >> endMin >> endSec;
- if (endHour < 0 || endHour > 23 || endMin < 0 || endMin > 59 || endSec < 0 || endSec > 59)
- cout << "Ошибка!!1!" << endl;
- else
- {
- timeSum = (endHour - startHour) * 3600 + (endMin - startMin) * 60 + (endSec - startSec);
- hour = (timeSum / 3600);
- min = (timeSum % 3600) / 60;
- sec = ((timeSum % 3600) % 60);
- cout << hour << ' ' << min << ' ' << sec << endl;
- }
- }
- system("pause"); //Delay
- }
- static void Task4()
- {
- double number1, number2, percent;
- cout << "Введите первое число: ";
- cin >> number1;
- cout << "Введите второе число: ";
- cin >> number2;
- percent = number1 / number2 * 100;
- cout << "Процентная часть первого числа от второго: " << percent << endl;
- system("pause"); //Delay
- }
- static void TaskList()
- {
- SetColor(15, 0);
- SetCursorPosition(29, 12); cout << "Основное задание:";
- SetCursorPosition(56, 12); cout << "Вариант 9";
- SetColor(11, 0);
- SetCursorPosition(29, 13); cout << "Дополнительные задания:";
- SetCursorPosition(56, 13); cout << "Задание 1";
- SetCursorPosition(56, 14); cout << "Задание 2";
- SetCursorPosition(56, 15); cout << "Задание 3";
- SetCursorPosition(29, 46); cout << "Управление:";
- SetCursorPosition(40, 47); cout << "Движение курсора стрелочками вверх и вниз";
- SetCursorPosition(40, 48); cout << "Выбор задания - стрелочка влево";
- SetCursorPosition(40, 49); cout << "Выход - ESC";
- }
- static void ChooseTask()
- {
- int y = 12;
- CursorVisible(false);
- SetColor(12, 0);
- while (true)
- {
- SetCursorPosition(65, y); cout << "<===";
- if (GetAsyncKeyState(VK_UP))
- if (y != 12)
- {
- SetCursorPosition(65, y); cout << " ";
- y -= 1;
- }
- if (GetAsyncKeyState(VK_DOWN))
- if (y != 15)
- {
- SetCursorPosition(65, y); cout << " ";
- y += 1;
- }
- if (GetAsyncKeyState(VK_LEFT))
- {
- system("cls");
- SetColor(15, 0);
- CursorVisible(true);
- switch (y)
- {
- case 12: Task1();
- break;
- case 13: Task2();
- break;
- case 14: Task3();
- break;
- case 15: Task4();
- break;
- }
- Sleep(1000);
- system("cls");
- return;
- }
- if (GetAsyncKeyState(VK_ESCAPE)) exit(1);
- Sleep(200);
- }
- }
- void main()
- {
- setlocale(LC_ALL, "Russian");
- system("mode con cols=100 lines=50");
- SetConsoleTitle("Laba 1"); //если ошибка, заменить на: system("title Laba 1");
- while (true)
- {
- ASCIILogo();
- TaskList();
- ChooseTask();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment