Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- #include <windows.h>
- #include <iomanip>
- 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 Box(int xPos, int yPos, int Weight, int Height)
- {
- for (int i = 0; i < Height; i++, yPos++)
- {
- SetCursorPosition(xPos, yPos);
- cout << setw(Weight) << ' ';
- }
- }
- HWND GetConsoleHwnd()
- {
- #define MY_BUFSIZE 1024
- HWND hwndFound;
- char pszNewWindowTitle[MY_BUFSIZE];
- char pszOldWindowTitle[MY_BUFSIZE];
- GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
- wsprintf(pszNewWindowTitle, "%d/%d",
- GetTickCount(),
- GetCurrentProcessId());
- SetConsoleTitle(pszNewWindowTitle);
- Sleep(1);
- hwndFound = FindWindow(NULL, pszNewWindowTitle);
- SetConsoleTitle(pszOldWindowTitle);
- return(hwndFound);
- }
- static void DrawLogo()
- {
- SetColor(15, 7);
- Box(0, 0, 80, 1);
- Box(0, 7, 80, 1);
- SetColor(15, 15);
- Box(0, 1, 23, 6);
- Box(58, 1, 22, 6);
- int image[6][38] =
- {
- { 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,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,15,15,15,12,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,15,12,12,12,15,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,15,15,15,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,12,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,15,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
- {
- system("cls");
- int count = 0, mark, sum;
- for (int i = 0; i < 77; i++) cout << '-';
- cout << "\nСтуденты: |";
- for (int i = 1; i <= 15; i++) cout << " " << i << " |";
- cout << endl;
- for (int i = 0; i < 77; i++) cout << '-';
- for (int i = 1; i <= 4; i++)
- {
- if (i < 4) cout << endl << i << " предмет |";
- else cout << endl << "Ср. балл |";
- for (int i = 1; i <= 15; i++)
- {
- if (i < 10) cout << " |";
- else cout << " |";
- }
- }
- cout << endl;
- for (int i = 0; i < 77; i++) cout << '-';
- for (int i = 1; i <= 15; i++)
- {
- sum = 0;
- bool whitoutBadMarks = true;
- for (int j = 1; j <= 3; j++)
- {
- do
- {
- SetCursorPosition(0, 9); cout << " \n \n ";
- SetCursorPosition(0, 8);
- cout << "Введите оценку " << i << "-го студента по " << j << "-му предмету. " << endl;
- cin >> mark;
- SetCursorPosition(0, 8);
- } while (!(mark > 0 && mark < 6));
- if (i < 10) SetCursorPosition(12 + (4 * (i - 1)), j + 2);
- else SetCursorPosition(48 + (5 * (i - 10)), j + 2);
- cout << mark;
- if (mark <= 2) whitoutBadMarks = false;
- sum += mark;
- }
- if (whitoutBadMarks) count++;
- if (i < 10) SetCursorPosition(12 + (4 * (i - 1)), 6);
- else SetCursorPosition(48 + (5 * (i - 10)), 6);
- cout << sum / 3 << endl;
- }
- SetCursorPosition(0, 10);
- cout << "Количество студентов без двоек: " << count << endl;
- cout << "Нажмите ESC для выхода.";
- while (true) if (GetAsyncKeyState(VK_ESCAPE)) break;
- }
- static void Task2() //Задание 2
- {
- int mounce = 0;
- double persent, money = 1000;
- do
- {
- system("cls");
- cout << "Введите процент(0 < P < 25): ";
- cin >> persent;
- } while (!(persent > 0 && persent < 25));
- while (money < 1100)
- {
- mounce++;
- money *= 1 + persent / 100;
- }
- cout << "Количество месяцев: " << mounce << endl;
- cout << "Итоговая сумма: " << money << endl;
- system("pause");
- }
- static void Task3() //Задание 3
- {
- int heigth;
- do
- {
- system("cls");
- cout << "Введите высоту полупирамиды: ";
- cin >> heigth;
- } while (!(heigth > 1 && heigth < 24));
- for (int y = 1; y <= heigth; y++)
- {
- SetCursorPosition(0, y + 3);
- for (int j = 1; j < heigth - y + 1; j++) cout << ' ';
- for (int a = 1; a < y + 2; a++) cout << '#';
- cout << endl;
- }
- system("pause");
- }
- static void Task4() //Задание 4
- {
- double credit;
- int balance;
- int _25cent = 0, _10cent = 0, _5cent = 0, _1cent = 0;
- do
- {
- system("cls");
- cout << "Введите долг продавца(Например 9.75): ";
- cin >> credit;
- } while (credit < 0);
- balance = (int)(credit * 100);
- while (balance > 0)
- {
- if (balance >= 25)
- {
- balance -= 25;
- _25cent++;
- }
- else if (balance >= 10)
- {
- balance -= 10;
- _10cent++;
- }
- else if (balance >= 5)
- {
- balance -= 5;
- _5cent++;
- }
- else if (balance >= 1)
- {
- balance -= 1;
- _1cent++;
- }
- }
- cout << "\nВам выдали монеты номиналом:\n\n";
- cout << "25 центов: " << _25cent << " шт.\n";
- cout << "10 центов: " << _10cent << " шт.\n";
- cout << "5 центов: " << _5cent << " шт.\n";
- cout << "1 цент: " << _1cent << " шт.\n";
- system("pause");
- }
- static void TaskList()
- {
- SetColor(9, 7);
- Box(0, 9, 80, 1);
- SetCursorPosition(5, 9); cout << "Основные задания:";
- SetCursorPosition(45, 9); cout << "Дополнительные:";
- SetColor(0, 12);
- Box(66, 24, 9, 3);
- SetCursorPosition(68, 25); cout << "Выход";
- SetColor(0, 15);
- Box(5, 12, 30, 3);
- Box(5, 16, 30, 3);
- Box(45, 12, 30, 3);
- Box(45, 16, 30, 3);
- SetCursorPosition(7, 13); cout << "Задание 1. Вариант 3.";
- SetCursorPosition(7, 17); cout << "Задание 2. Вариант 9.";
- SetCursorPosition(47, 13); cout << "Дополнительное задание 1";
- SetCursorPosition(47, 17); cout << "Дополнительное задание 2";
- SetColor(9, 7);
- Box(0, 21, 80, 1);
- SetCursorPosition(5, 21); cout << "Управление:";
- SetColor(15, 0);
- SetCursorPosition(5, 24); cout << "Движение курсора мышью.";
- SetCursorPosition(5, 26); cout << "Выбор задания - ПКМ.";
- }
- static void ChooseTask()
- {
- int xPos, yPos;
- RECT r;
- POINT p;
- HWND wh = GetConsoleHwnd();
- COORD c = { 1,1 };
- while (true)
- {
- GetWindowRect(wh, &r);
- GetCursorPos(&p);
- xPos = (p.x - r.left - 9) / 8; //Координаты X для вин7 и вин10
- yPos = (p.y - r.top - 30) / 12; //Координаты Y для вин7
- //yPos = (p.y - r.top - 30) / 16; //Координаты Y для вин10
- SetCursorPosition(xPos, yPos);
- if (GetAsyncKeyState(VK_LBUTTON))
- {
- if (xPos >= 5 && xPos <= 35 && yPos >= 12 && yPos <= 14)
- {
- Task1();
- system("cls");
- return;
- }
- else if (xPos >= 5 && xPos <= 35 && yPos >= 16 && yPos <= 18)
- {
- Task2();
- system("cls");
- return;
- }
- else if (xPos >= 45 && xPos <= 74 && yPos >= 12 && yPos <= 14)
- {
- Task3();
- system("cls");
- return;
- }
- else if (xPos >= 45 && xPos <= 74 && yPos >= 16 && yPos <= 18)
- {
- Task4();
- system("cls");
- return;
- }
- else if (xPos >= 66 && xPos <= 74 && yPos >= 24 && yPos <= 26) exit(1);
- }
- }
- }
- void main()
- {
- setlocale(LC_ALL, "Russian");
- system("mode con cols=80 lines=40");
- system("title Laba 3");
- while (true)
- {
- DrawLogo();
- TaskList();
- ChooseTask();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement