Advertisement
ResistanceJke

lab6

Dec 2nd, 2019
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.75 KB | None | 0 0
  1. // Прога выводит график, зарисовывает минимальный, максимальный элемент и зарисовывает цветом чётные элементы, расположенные между min max
  2.  
  3. #include "framework.h"
  4. #include "lab6.h"
  5.  
  6. #define MAX_LOADSTRING 100
  7.  
  8. int a[5] = { 100,31,70,-57,62 };
  9. void zxc(HDC hdc, int x, int y, int p)
  10. {
  11.  
  12.     HBRUSH hpen0 = CreateSolidBrush(RGB(255, 0, 0));
  13.     HBRUSH hbrush0 = CreateSolidBrush(RGB(255, 255, 255));
  14.     HBRUSH MinBrush = CreateSolidBrush(RGB(123, 123, 245));
  15.     HBRUSH MaxBrush = CreateSolidBrush(RGB(210, 123, 234));
  16.     int max = 0;
  17.     int min = 100;
  18.     int imax = 0;
  19.     int imin = 0;
  20.     for (int i = 0; i < 5; i++)
  21.     {
  22.         if (a[i] < min) {
  23.             min = a[i];
  24.             imin = i;
  25.         }
  26.         if (a[i] > max) {
  27.             max = a[i];
  28.             imax = i;
  29.         }
  30.     }
  31.     if (imin > imax)
  32.     {
  33.         int temp = imin;
  34.         imin = imax;
  35.         imax = temp;
  36.     }
  37.     int cx = 0;
  38.     int ry = 150;
  39.     int rx = 300;
  40.     for (int i = 0; i < p; i++)
  41.     {
  42.         SelectObject(hdc, hbrush0);
  43.         if ((i < imax) && (i > imin) && (a[i] % 2 == 0))
  44.         {
  45.             SelectObject(hdc, hpen0);
  46.         }
  47.         if (i == imax)
  48.         {
  49.             SelectObject(hdc, MaxBrush);
  50.         }
  51.         if (i == imin)
  52.         {
  53.             SelectObject(hdc, MinBrush);
  54.         }
  55.         Rectangle(hdc, x + cx, y - a[i], x + cx + 40, y);
  56.         cx += 40;
  57.     }
  58.     MoveToEx(hdc, x, y, NULL);
  59.     LineTo(hdc, x, y - ry);
  60.     LineTo(hdc, x, y - ry);
  61.     LineTo(hdc, x + 10, y - ry + 20);
  62.     MoveToEx(hdc, x, y - ry, NULL);
  63.     LineTo(hdc, x - 10, y - ry + 20);
  64.     MoveToEx(hdc, x, y, NULL);
  65.     LineTo(hdc, x, y + ry);
  66.     LineTo(hdc, x, y + ry);
  67.     LineTo(hdc, x + 10, y + ry - 20);
  68.     MoveToEx(hdc, x, y + ry, NULL);
  69.     LineTo(hdc, x - 10, y + ry - 20);
  70.  
  71.     MoveToEx(hdc, x, y, NULL);
  72.     LineTo(hdc, x + rx, y);
  73.     LineTo(hdc, x + rx - 10, y + 20);
  74.     MoveToEx(hdc, x + rx, y, NULL);
  75.     LineTo(hdc, x + rx - 10, y - 20);
  76.  
  77. }
  78.  
  79. void zxcmain(HDC hdc, int x, int y, int p)
  80. {
  81.     int max = 0;
  82.     int min = 100;
  83.     int imax = 0;
  84.     int imin = 0;
  85.     for (int i = 0; i < 5; i++)
  86.     {
  87.         if (a[i] < min) {
  88.             min = a[i];
  89.             imin = i;
  90.         }
  91.         if (a[i] > max) {
  92.             max = a[i];
  93.             imax = i;
  94.         }
  95.     }
  96.     int cx = 0;
  97.     int ry = 150;
  98.     int rx = 300;
  99.     for (int i = 0; i < p; i++)
  100.     {
  101.         Rectangle(hdc, x + cx, y - a[i], x + cx + 40, y);
  102.         cx += 40;
  103.     }
  104.     MoveToEx(hdc, x, y, NULL);
  105.     LineTo(hdc, x, y - ry);
  106.     LineTo(hdc, x, y - ry);
  107.     LineTo(hdc, x + 10, y - ry + 20);
  108.     MoveToEx(hdc, x, y - ry, NULL);
  109.     LineTo(hdc, x - 10, y - ry + 20);
  110.     MoveToEx(hdc, x, y, NULL);
  111.     LineTo(hdc, x, y + ry);
  112.     LineTo(hdc, x, y + ry);
  113.     LineTo(hdc, x + 10, y + ry - 20);
  114.     MoveToEx(hdc, x, y + ry, NULL);
  115.     LineTo(hdc, x - 10, y + ry - 20);
  116.  
  117.     MoveToEx(hdc, x, y, NULL);
  118.     LineTo(hdc, x + rx, y);
  119.     LineTo(hdc, x + rx - 10, y + 20);
  120.     MoveToEx(hdc, x + rx, y, NULL);
  121.     LineTo(hdc, x + rx - 10, y - 20);
  122.  
  123. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement