Advertisement
PhotoShaman

Laba3

Nov 29th, 2016
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 8.51 KB | None | 0 0
  1. #include <iostream>
  2. #include <clocale>
  3. #include <windows.h>
  4. #include <iomanip>
  5.  
  6. using namespace std;
  7.  
  8. static void SetCursorPosition(int x, int y)
  9. {
  10.     COORD coord;
  11.     coord.X = x;
  12.     coord.Y = y;
  13.     SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
  14. }
  15. enum ConsoleColor
  16. {
  17.     Black = 0,
  18.     Blue = 1,
  19.     Green = 2,
  20.     Cyan = 3,
  21.     Red = 4,
  22.     Magenta = 5,
  23.     Brown = 6,
  24.     LightGray = 7,
  25.     DarkGray = 8,
  26.     LightBlue = 9,
  27.     LightGreen = 10,
  28.     LightCyan = 11,
  29.     LightRed = 12,
  30.     LightMagenta = 13,
  31.     Yellow = 14,
  32.     White = 15
  33. };
  34. static void SetColor(int text, int background) // устанавливает цвет текста и фона в консоли
  35. {
  36.     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  37.     SetConsoleTextAttribute(hStdOut, (WORD)((background << 4) | text));
  38. }
  39. static void SetColor(int text, ConsoleColor/*int*/ background) // устанавливает цвет текста и фона в консоли
  40. {
  41.     HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
  42.     SetConsoleTextAttribute(hStdOut, (WORD)((background << 4) | text));
  43. }
  44. static void Box(int xPos, int yPos, int Weight, int Height)
  45. {
  46.     for (int i = 0; i < Height; i++, yPos++)
  47.     {
  48.         SetCursorPosition(xPos, yPos);
  49.         cout << setw(Weight) << ' ';
  50.     }
  51. }
  52. HWND GetConsoleHwnd()
  53. {
  54. #define MY_BUFSIZE 1024
  55.     HWND hwndFound;
  56.     char pszNewWindowTitle[MY_BUFSIZE];
  57.     char pszOldWindowTitle[MY_BUFSIZE];
  58.     GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
  59.     wsprintf(pszNewWindowTitle, "%d/%d",
  60.         GetTickCount(),
  61.         GetCurrentProcessId());
  62.     SetConsoleTitle(pszNewWindowTitle);
  63.     Sleep(1);
  64.     hwndFound = FindWindow(NULL, pszNewWindowTitle);
  65.     SetConsoleTitle(pszOldWindowTitle);
  66.     return(hwndFound);
  67. }
  68. static void DrawLogo()
  69. {
  70.     SetColor(15, 7);
  71.     Box(0, 0, 80, 1);
  72.     Box(0, 7, 80, 1);
  73.  
  74.     SetColor(15, 15);
  75.     Box(0, 1, 23, 6);
  76.     Box(58, 1, 22, 6);
  77.  
  78.     int image[6][38] =
  79.     {
  80.         { 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 },
  81.         { 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 },
  82.         { 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 },
  83.         { 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 },
  84.         { 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 },
  85.         { 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 }
  86.     };
  87.  
  88.     SetCursorPosition(23, 1);
  89.  
  90.     for (int i = 0; i < 6;)
  91.     {
  92.         for (int j = 0; j <= 38; j++)
  93.         {
  94.             if (image[i][j] == 16)
  95.             {
  96.                 i++;
  97.                 SetCursorPosition(23, i + 1); break;
  98.             }
  99.             else if (image[i][j] > 0)
  100.             {
  101.                 SetColor(15, image[i][j]);
  102.                 cout << ' ';
  103.             }
  104.         }
  105.     }
  106.     SetCursorPosition(0, 0);
  107. }
  108. static void Task1() //Задание 1
  109. {
  110.     system("cls");
  111.     int count = 0, mark, sum;
  112.  
  113.     for (int i = 0; i < 77; i++) cout << '-';
  114.     cout << "\nСтуденты: |";
  115.     for (int i = 1; i <= 15; i++) cout << " " << i << " |";
  116.     cout << endl;
  117.     for (int i = 0; i < 77; i++) cout << '-';
  118.  
  119.     for (int i = 1; i <= 4; i++)
  120.     {
  121.         if (i < 4) cout << endl << i << " предмет |";
  122.         else cout << endl << "Ср. балл  |";
  123.         for (int i = 1; i <= 15; i++)
  124.         {
  125.             if (i < 10) cout << "   |";
  126.             else cout << "    |";
  127.         }
  128.     }
  129.     cout << endl;
  130.     for (int i = 0; i < 77; i++) cout << '-';
  131.  
  132.     for (int i = 1; i <= 15; i++)
  133.     {
  134.         sum = 0;
  135.         bool whitoutBadMarks = true;
  136.         for (int j = 1; j <= 3; j++)
  137.         {
  138.             do
  139.             {
  140.                 SetCursorPosition(0, 9); cout << "         \n        \n         ";
  141.                 SetCursorPosition(0, 8);
  142.                 cout << "Введите оценку " << i << "-го студента по " << j << "-му предмету.    " << endl;
  143.                 cin >> mark;
  144.                 SetCursorPosition(0, 8);
  145.             } while (!(mark > 0 && mark < 6));
  146.             if (i < 10) SetCursorPosition(12 + (4 * (i - 1)), j + 2);
  147.             else SetCursorPosition(48 + (5 * (i - 10)), j + 2);
  148.             cout << mark;
  149.             if (mark <= 2) whitoutBadMarks = false;
  150.             sum += mark;
  151.         }
  152.         if (whitoutBadMarks) count++;
  153.         if (i < 10) SetCursorPosition(12 + (4 * (i - 1)), 6);
  154.         else SetCursorPosition(48 + (5 * (i - 10)), 6);
  155.         cout << sum / 3 << endl;
  156.     }
  157.     SetCursorPosition(0, 10);
  158.     cout << "Количество студентов без двоек: " << count << endl;
  159.     cout << "Нажмите ESC для выхода.";
  160.     while (true) if (GetAsyncKeyState(VK_ESCAPE)) break;
  161. }
  162. static void Task2() //Задание 2
  163. {
  164.     int mounce = 0;
  165.     double persent, money = 1000;
  166.  
  167.     do
  168.     {
  169.         system("cls");
  170.         cout << "Введите процент(0 < P < 25): ";
  171.         cin >> persent;
  172.     } while (!(persent > 0 && persent < 25));
  173.  
  174.     while (money < 1100)
  175.     {
  176.         mounce++;
  177.         money *= 1 + persent / 100;
  178.     }
  179.  
  180.     cout << "Количество месяцев: " << mounce << endl;
  181.     cout << "Итоговая сумма: " << money << endl;
  182.  
  183.     system("pause");
  184. }
  185. static void Task3() //Задание 3
  186. {
  187.     int heigth;
  188.  
  189.     do
  190.     {
  191.         system("cls");
  192.         cout << "Введите высоту полупирамиды: ";
  193.         cin >> heigth;
  194.     } while (!(heigth > 1 && heigth < 24));
  195.  
  196.     for (int y = 1; y <= heigth; y++)
  197.     {
  198.         SetCursorPosition(0, y + 3);
  199.         for (int j = 1; j < heigth - y + 1; j++) cout << ' ';
  200.         for (int a = 1; a < y + 2; a++) cout << '#';
  201.         cout << endl;
  202.     }
  203.     system("pause");
  204. }
  205. static void Task4() //Задание 4
  206. {
  207.     double credit;
  208.     int balance;
  209.     int _25cent = 0, _10cent = 0, _5cent = 0, _1cent = 0;
  210.  
  211.     do
  212.     {
  213.         system("cls");
  214.         cout << "Введите долг продавца(Например 9.75): ";
  215.         cin >> credit;
  216.     } while (credit < 0);
  217.  
  218.     balance = (int)(credit * 100);
  219.  
  220.     while (balance > 0)
  221.     {
  222.         if (balance >= 25)
  223.         {
  224.             balance -= 25;
  225.             _25cent++;
  226.         }
  227.         else if (balance >= 10)
  228.         {
  229.             balance -= 10;
  230.             _10cent++;
  231.         }
  232.         else if (balance >= 5)
  233.         {
  234.             balance -= 5;
  235.             _5cent++;
  236.         }
  237.         else if (balance >= 1)
  238.         {
  239.             balance -= 1;
  240.             _1cent++;
  241.         }
  242.     }
  243.  
  244.     cout << "\nВам выдали монеты номиналом:\n\n";
  245.     cout << "25 центов: " << _25cent << " шт.\n";
  246.     cout << "10 центов: " << _10cent << " шт.\n";
  247.     cout << "5  центов: " << _5cent << " шт.\n";
  248.     cout << "1  цент:   " << _1cent << " шт.\n";
  249.     system("pause");
  250. }
  251. static void TaskList()
  252. {
  253.     SetColor(9, 7);
  254.     Box(0, 9, 80, 1);
  255.  
  256.     SetCursorPosition(5, 9); cout << "Основные задания:";
  257.     SetCursorPosition(45, 9); cout << "Дополнительные:";
  258.  
  259.     SetColor(0, 12);
  260.     Box(66, 24, 9, 3);
  261.     SetCursorPosition(68, 25); cout << "Выход";
  262.  
  263.     SetColor(0, 15);
  264.     Box(5, 12, 30, 3);
  265.     Box(5, 16, 30, 3);
  266.     Box(45, 12, 30, 3);
  267.     Box(45, 16, 30, 3);
  268.  
  269.     SetCursorPosition(7, 13);  cout << "Задание 1. Вариант 3.";
  270.     SetCursorPosition(7, 17);  cout << "Задание 2. Вариант 9.";
  271.     SetCursorPosition(47, 13); cout << "Дополнительное задание 1";
  272.     SetCursorPosition(47, 17); cout << "Дополнительное задание 2";
  273.  
  274.     SetColor(9, 7);
  275.     Box(0, 21, 80, 1);
  276.     SetCursorPosition(5, 21); cout << "Управление:";
  277.  
  278.     SetColor(15, 0);
  279.     SetCursorPosition(5, 24); cout << "Движение курсора мышью.";
  280.     SetCursorPosition(5, 26); cout << "Выбор задания - ПКМ.";
  281. }
  282. static void ChooseTask()
  283. {
  284.     int xPos, yPos;
  285.     RECT r;
  286.     POINT p;
  287.     HWND wh = GetConsoleHwnd();
  288.     COORD c = { 1,1 };
  289.     while (true)
  290.     {
  291.         GetWindowRect(wh, &r);
  292.         GetCursorPos(&p);
  293.         xPos = (p.x - r.left - 9) / 8; //Координаты X для вин7 и вин10
  294.         yPos = (p.y - r.top - 30) / 12; //Координаты Y для вин7
  295.         //yPos = (p.y - r.top - 30) / 16; //Координаты Y для вин10
  296.         SetCursorPosition(xPos, yPos);
  297.  
  298.         if (GetAsyncKeyState(VK_LBUTTON))
  299.         {
  300.             if (xPos >= 5 && xPos <= 35 && yPos >= 12 && yPos <= 14)
  301.             {
  302.                 Task1();
  303.                 system("cls");
  304.                 return;
  305.             }
  306.             else if (xPos >= 5 && xPos <= 35 && yPos >= 16 && yPos <= 18)
  307.             {
  308.                 Task2();
  309.                 system("cls");
  310.                 return;
  311.             }
  312.             else if (xPos >= 45 && xPos <= 74 && yPos >= 12 && yPos <= 14)
  313.             {
  314.                 Task3();
  315.                 system("cls");
  316.                 return;
  317.             }
  318.             else if (xPos >= 45 && xPos <= 74 && yPos >= 16 && yPos <= 18)
  319.             {
  320.                 Task4();
  321.                 system("cls");
  322.                 return;
  323.             }
  324.             else if (xPos >= 66 && xPos <= 74 && yPos >= 24 && yPos <= 26) exit(1);
  325.  
  326.         }
  327.     }
  328. }
  329. void main()
  330. {
  331.     setlocale(LC_ALL, "Russian");
  332.     system("mode con cols=80 lines=40");
  333.     system("title Laba 3");
  334.     while (true)
  335.     {
  336.         DrawLogo();
  337.         TaskList();
  338.         ChooseTask();
  339.     }
  340. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement