Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- #include <cmath>
- #include <windows.h>
- #include <iomanip>
- #include <conio.h>
- 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 Box(int xPos, int yPos, int Weight, int Height)
- {
- for (int i = 0; i < Height; i++, yPos++)
- {
- SetCursorPosition(xPos, yPos);
- cout << setw(Weight) << ' ';
- }
- }
- static void ASCIILogo()
- {
- SetColor(15, 7);
- Box(0, 0, 80, 1);
- Box(0, 7, 80, 1);
- SetColor(15, 15);
- Box(0, 1, 23, 6);
- Box(59, 1, 21, 6);
- int image[6][37] =
- {
- { 12,12,15,15,15,15,15,12,12,12,12,15,15,15,12,12,12,12,12,12,15,15,15,15,15,12,12,12,12,15,15,15,12,12,12,12,16 },
- { 12,12,15,15,15,15,12,12,15,15,12,12,15,15,12,12,15,15,15,15,12,12,15,15,12,12,15,15,12,12,15,15,15,15,15,12,16 },
- { 12,12,15,15,15,15,12,12,15,15,12,12,15,15,12,12,12,12,12,12,15,15,15,15,12,12,15,15,12,12,15,15,12,12,12,12,16 },
- { 12,12,15,15,15,15,12,12,12,12,12,12,15,15,12,12,15,15,15,15,12,12,15,15,12,12,12,12,12,12,15,15,12,15,15,15,16 },
- { 12,12,15,15,15,15,12,12,15,15,12,12,15,15,12,12,15,15,15,15,12,12,15,15,12,12,15,15,12,12,15,15,12,15,15,15,16 },
- { 12,12,12,12,15,15,12,12,15,15,12,12,15,15,12,12,12,12,12,12,15,15,15,15,12,12,15,15,12,12,15,15,12,12,12,12,16 }
- };
- SetCursorPosition(23, 1);
- for (int i = 0; i < 6;)
- {
- for (int j = 0; j < 38; j++)
- {
- if (image[i][j] == 16)
- {
- i++;
- SetCursorPosition(23, i + 1); break;
- }
- else if (image[i][j] > 0)
- {
- SetColor(15, image[i][j]);
- cout << ' ';
- }
- }
- }
- SetCursorPosition(0, 0);
- }
- static void Task1() //Задание 1
- {
- int x1, x2, x3, y1, y2, y3;
- double lineAB, lineBC, lineAC;
- cout << "Введите координату первой точки треугольника A(x1, y1). Например: 2 5\n";
- cin >> x1 >> y1;
- cout << "\nВведите координату второй точки треугольника B(x2, y2). Например: 5 1\n";
- cin >> x2 >> y2;
- cout << "\nВведите координату третей точки треугольника C(x3 y3). Например: 11 3\n";
- cin >> x3 >> y3;
- lineAB = sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2));
- lineBC = sqrt((x2 - x3) * (x2 - x3) + (y2 - y3) * (y2 - y3));
- lineAC = sqrt((x1 - x3) * (x1 - x3) + (y1 - y3) * (y1 - y3));
- if (lineAB < lineBC && lineAB < lineAC) cout << "Сторона AB найменьшая.";
- else if (lineBC < lineAB && lineBC < lineAC) cout << "Сторона BC найменьшая.";
- else if (lineAC < lineAB && lineAC < lineBC) cout << "Сторона AC найменьшая.";
- else if (lineAB == lineBC && lineAB == lineAC) cout << "Стороны AB, BC и AC равны.";
- else if (lineAB == lineBC && lineAB > lineAC) cout << "Сторона AC найменьшая, а стороны AB и BC равны";
- else if (lineAB == lineBC && lineAB < lineAC) cout << "Стороны AB и BC равны и меньше стороны AC";
- else if (lineAC == lineBC && lineAC > lineAB) cout << "Сторона AB найменьшая, а стороны AC и BC равны";
- else if (lineAC == lineBC && lineAC < lineAB) cout << "Стороны AC и BC равны и меньше стороны AB";
- else if (lineAB == lineAC && lineAB > lineBC) cout << "Сторона BC найменьшая, а стороны AB и AC равны";
- else if (lineAB == lineAC && lineAB < lineBC) cout << "Стороны AB и AC равны и меньше стороны BC";
- else cout << "Что-то пошло не так...";
- cout << endl;
- system("pause");
- system("cls");
- }
- static void Task2() //Задание 2
- {
- float number1, number2;
- char action;
- cout << "Введите операцию для калькулятора. Например: 3 * 5.\n\n";
- cout << "Доступные действия: сложение: +\n";
- cout << " вычитание: -\n";
- cout << " умножение: *\n";
- cout << " деление: /\n";
- cin >> number1 >> action >> number2;
- switch (action)
- {
- case '+': cout << number1 + number2; break;
- case '-': cout << number1 - number2; break;
- case '*': cout << number1 * number2; break;
- case '/': cout << number1 / number2; break;
- default: cout << "Что-то пошло не так...";
- break;
- }
- cout << endl;
- system("pause");
- system("cls");
- }
- static void Task3() //Задание 3
- {
- int a, b, c;
- cout << "Введите числа a, b и c. Например: 3 4 5.\n";
- cin >> a >> b >> c;
- if (a + b > c && c + b > a && a + c > b) cout << "\nTriangle\n";
- else cout << "\nNot triangle\n";
- //Предыдущий вариант
- //if (a + b < c || c + b < a || a + c < b) cout << "\nNot triangle\n";
- //else cout << "\nTriangle\n";
- system("pause");
- system("cls");
- }
- static void Task4() //Задание 4
- {
- int number;
- cout << "Введите число от 100 до 999: ";
- cin >> number;
- if (number >= 100 && number <= 999)
- {
- switch (number / 100)
- {
- case 1: cout << "Сто "; break;
- case 2: cout << "Двести "; break;
- case 3: cout << "Триста "; break;
- case 4: cout << "Четыреста "; break;
- case 5: cout << "Пятьсот "; break;
- case 6: cout << "Шестьсот "; break;
- case 7: cout << "Семьсот "; break;
- case 8: cout << "Восемьсот "; break;
- case 9: cout << "Девятьсот "; break;
- }
- if (number % 100 > 10 && number % 100 < 21)
- {
- switch (number % 100)
- {
- case 11: cout << "одиннадцать"; break;
- case 12: cout << "двенадцать"; break;
- case 13: cout << "тринадцать"; break;
- case 14: cout << "четырнадцать"; break;
- case 15: cout << "пятнадцать"; break;
- case 16: cout << "шестнадцать"; break;
- case 17: cout << "семнадцать"; break;
- case 18: cout << "восемнадцать"; break;
- case 19: cout << "девятнадцать"; break;
- case 20: cout << "двадцать"; break;
- }
- }
- else
- {
- switch (number % 100 / 10)
- {
- case 0: break;
- case 1: cout << "десять "; break;
- case 2: cout << "двадцать "; break;
- case 3: cout << "тридцать "; break;
- case 4: cout << "сорок "; break;
- case 5: cout << "пятьдесят "; break;
- case 6: cout << "шестьдесят "; break;
- case 7: cout << "семьдесят "; break;
- case 8: cout << "восемьдесят "; break;
- case 9: cout << "девяносто "; break;
- }
- switch (number % 100 % 10)
- {
- case 0: break;
- case 1: cout << "один"; break;
- case 2: cout << "два"; break;
- case 3: cout << "три"; break;
- case 4: cout << "четыре"; break;
- case 5: cout << "пять"; break;
- case 6: cout << "шесть"; break;
- case 7: cout << "семь"; break;
- case 8: cout << "восемь"; break;
- case 9: cout << "девять"; break;
- }
- }
- }
- else
- {
- cout << "Ошибка условия";
- }
- cout << endl;
- system("pause"); //Delay
- }
- static void TaskList()
- {
- SetColor(9, 7);
- Box(0, 9, 80, 1);
- SetCursorPosition(23, 9);
- cout << "Основные задания:";
- SetCursorPosition(44, 9);
- cout << "Дополнительные:";
- SetColor(0, 15);
- Box(23, 12, 5, 3);
- Box(33, 12, 5, 3);
- Box(44, 12, 5, 3);
- Box(54, 12, 5, 3);
- SetCursorPosition(25, 13);
- cout << '1';
- SetCursorPosition(35, 13);
- cout << '2';
- SetCursorPosition(46, 13);
- cout << '3';
- SetCursorPosition(56, 13);
- cout << '4';
- SetColor(9, 7);
- Box(0, 17, 80, 1);
- SetCursorPosition(23, 17);
- cout << "Управление:";
- SetColor(15, 0);
- SetCursorPosition(23, 19); cout << "Движение курсора стрелочками влево и вправо.";
- SetCursorPosition(23, 21); cout << "Выбор задания - стрелочка вверх.";
- SetCursorPosition(23, 23); cout << "Выход - ESC.";
- }
- static void ChooseTask()
- {
- int x = 23;
- CursorVisible(false);
- SetColor(0, 15);
- while (true)
- {
- SetCursorPosition(x, 12); cout << "/---\\";
- SetCursorPosition(x, 13); cout << "|"; SetCursorPosition(x + 4, 13); cout << "|";
- SetCursorPosition(x, 14); cout << "\\---/";
- Sleep(100);
- SetCursorPosition(x, 12); cout << "-\\\\\\|";
- SetCursorPosition(x, 13); cout << "/"; SetCursorPosition(x + 4, 13); cout << "/";
- SetCursorPosition(x, 14); cout << "|\\\\\\-";
- Sleep(100);
- SetCursorPosition(x, 12); cout << "\\|||/";
- SetCursorPosition(x, 13); cout << "-"; SetCursorPosition(x + 4, 13); cout << "-";
- SetCursorPosition(x, 14); cout << "/|||\\";
- Sleep(100);
- SetCursorPosition(x, 12); cout << "|///-";
- SetCursorPosition(x, 13); cout << "\\"; SetCursorPosition(x + 4, 13); cout << "\\";
- SetCursorPosition(x, 14); cout << "-///|";
- Sleep(50);
- switch (_getch())
- {
- case 75: //Влево
- if (x != 23)
- {
- SetCursorPosition(x, 12); cout << " ";
- SetCursorPosition(x, 13); cout << " "; SetCursorPosition(x + 4, 13); cout << " ";
- SetCursorPosition(x, 14); cout << " ";
- if (x != 44) x -= 10;
- else x -= 11;
- }
- break;
- case 77: //Вправо
- if (x != 54)
- {
- SetCursorPosition(x, 12); cout << " ";
- SetCursorPosition(x, 13); cout << " "; SetCursorPosition(x + 4, 13); cout << " ";
- SetCursorPosition(x, 14); cout << " ";
- if (x != 33) x += 10;
- else x += 11;
- }
- break;
- case 72: //Вверх
- SetColor(15, 0);
- system("cls");
- CursorVisible(true);
- switch (x)
- {
- case 23: Task1(); break;
- case 33: Task2(); break;
- case 44: Task3(); break;
- case 54: Task4(); break;
- }
- Sleep(1000);
- system("cls");
- return;
- case 27: //Esc
- exit(1);
- Sleep(200);
- break;
- }
- }
- }
- void main()
- {
- setlocale(LC_ALL, "Russian");
- system("mode con cols=80 lines=40");
- //SetConsoleTitle("Laba 2"); //если ошибка, заменить на: system("title Laba 2");
- system("title Laba 2");
- while (true)
- {
- ASCIILogo();
- TaskList();
- ChooseTask();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment