Advertisement
GROZGRI

Test

Dec 9th, 2019
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.59 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3. #include <stdio.h>
  4. #include <ctime>
  5.  
  6. HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
  7. using namespace std;
  8.  
  9. const short FD_color = 12;
  10. const short FP_color = 14;
  11. const short SD_color = 11;
  12. const short SP_color = 9;
  13. const short DD_color = 10;
  14. const short PP_color = 13;
  15.  
  16. void color(int value, int colorID, bool endline = false)
  17. {
  18.     SetConsoleTextAttribute(handle, colorID);
  19.     cout << '\t' << value;
  20.     if (endline)
  21.     {
  22.         cout << endl;
  23.     }
  24.     SetConsoleTextAttribute(handle, 15);
  25. }
  26.  
  27. void arrwork(int x, int y)
  28. {
  29.     srand((unsigned)time(NULL));
  30.     int sizeline(y*5), matrix, DD(0), PP(0), FD(0), FP(0), SD(0), SP(0), sum(0); //F-first, S-second, P-parallel, D-diagonal.
  31.     system("cls");
  32.     cout << "\n\tМатрица:\n";
  33.  
  34.  
  35.     for (int i = 0; i < x; i++)
  36.     {
  37.         for (int j = 0; j < y; j++)
  38.         {
  39.             matrix = 11 + rand() % 88;
  40.             sum += matrix;
  41.  
  42.             if ((i == j) && (y - j == i + 1) ) //Пересекающие диагонали
  43.             {
  44.                 color(matrix, DD_color);
  45.                 DD += matrix; FD += matrix; SD += matrix;
  46.             }
  47.             else if ( ((i - 1 == j) || (i + 1 == j)) && ((y - j == i + 2) || (y - j == i)) ) //Пересекающие параллели
  48.             {
  49.                 color(matrix, PP_color);
  50.                 PP += matrix; FP += matrix; SP += matrix;
  51.             }
  52.             else if (i == j) //Главная диагональ
  53.             {
  54.                 color(matrix, FD_color);
  55.                 FD += matrix;
  56.             }
  57.             else if (y - j == i + 1) // Побочная диагональ
  58.             {
  59.                 color(matrix, SD_color);
  60.                 SD += matrix;
  61.             }
  62.             else if ((i - 1 == j) || (i + 1 == j)) //Главные параллели
  63.             {
  64.                 color(matrix, FP_color);
  65.                 FP += matrix;
  66.             }
  67.             else if ((y - j == i + 2) || (y - j == i)) //Побочные параллели
  68.             {
  69.                 color(matrix, SP_color);
  70.                 SP += matrix;
  71.             }
  72.             else //Остальное
  73.             {
  74.                 cout << '\t' << matrix;
  75.             }
  76.         }
  77.         cout << endl << endl;
  78.     }
  79.     cout << "\n\tСумма главной диагонали: "; color(FD, FD_color, true);
  80.     cout << "\tСумма параллельных линий ГД: "; color(FP, FP_color, true);
  81.     cout << "\tСумма побочной диагонали: "; color(SD, SD_color, true);
  82.     cout << "\tСумма параллельных линий ПД: "; color(SP, SP_color, true);
  83.     cout << endl;
  84.     cout << "\tОбщая сумма всех элементов: "; color(sum, 15, true);
  85.    
  86.     if (DD!=0)
  87.     {
  88.         cout << "\tСумма пересекающих диагоналей: "; color(DD, DD_color, true);
  89.         cout << "\tСумма пересекающих параллелей: "; color(PP, PP_color, true);
  90.     }
  91.     cout << endl;
  92.  
  93.     if (x == y)
  94.         cout << "\tДанная матрица является квадратной\n\n";
  95.     else
  96.         cout << "\n\tДанная матрица не является квадратной\n";
  97.     cout << "\tВсего строк в матрице:    "; color(x, FP_color, true);
  98.     cout << "\tВсего столбцов в матрице: "; color(y, FP_color, true);
  99.     cout << "\tВсего элементов в матрице: "; color(x*y, FD_color, false);
  100.     cout << endl << endl;
  101. }
  102.  
  103. int main()
  104. {
  105.     SetConsoleTextAttribute(handle, 15);
  106.     setlocale(LC_ALL, "ru");
  107.     system("title Работа с матрицами");
  108.     cout << "Разработчики - Гришин Данил Витальевич и Лера Ренатова\n\n";
  109.     int x, y;
  110.     while (true)
  111.     {
  112.         cout << "Введите x и y матрицы:\n(Введите нулевую матрицу, чтобы завершить работу)\n"; cin >> x >> y;
  113.         if ((x == 0) && (y == 0)) break;
  114.         arrwork (x,y);
  115.     }
  116.     return 0;
  117. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement