Advertisement
Soverein

Untitled

Sep 25th, 2021
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include<random>
  4. #include<algorithm>
  5. #include<math.h>
  6. using namespace std;
  7.  
  8. class MyClass
  9. {
  10. public:
  11. int collumn, row;
  12. MyClass(int n = 5, int m = 5)
  13. {
  14. row = n;
  15. collumn = m;
  16. for (int i = 0; i < n; i++)
  17. {
  18. vector<int> matrix2;
  19. for (int j=0;j<m;j++)
  20. {
  21. int randss = rand() % 10;
  22. matrix2.push_back(randss);
  23. cout << randss << "\t";
  24. }
  25. matrix.push_back(matrix2);
  26. cout << "\n";
  27. }
  28.  
  29. }
  30.  
  31. void buildMatr()
  32. {
  33. for (int i = 0; i < row; i++)
  34. {
  35. for (int j = 0; j < collumn; j++)
  36. {
  37. cout << matrix[i][j] << "\t";
  38. }
  39. cout << "\n";
  40. }
  41. }
  42.  
  43. void even()
  44. {
  45. int count = 0;
  46. for (int i=0;i<this->row;i++)
  47. {
  48. for (int j = 0; j < this->collumn; j++)
  49. {
  50. if (!(this->matrix[i][j] % 2))
  51. count++;
  52. }
  53. }
  54. cout << "\ncount= " << count << "\n";
  55. }
  56.  
  57. void diap(int A,int B)
  58. {
  59. int dob = 1;
  60. int rowA = A / this->row;
  61. int collA = A % this->collumn;
  62. while (A != B+1)
  63. {
  64. A++;
  65. dob *= this->matrix[rowA][collA++];
  66. if (collA > 4)
  67. {
  68. collA = 0;
  69. rowA++;
  70. }
  71. }
  72. cout << "\ndob = " << dob << endl << endl;
  73. }
  74. void ABSsort()
  75. {
  76. cout << "ABSsort :: \n";
  77. for (int i = 0; i < this->row; i++)
  78. {
  79. sort(this->matrix[i].begin(), this->matrix[i].end(), [](int a, int b)
  80. {
  81. return abs(a) > abs(b);
  82. });
  83. }
  84. cout << endl;
  85. this->buildMatr();
  86. }
  87. vector<vector<int>> matrix;
  88. };
  89. int main()
  90. {
  91. MyClass* VEK = new MyClass();
  92. VEK->even();
  93. VEK->diap(0, 3);
  94. VEK->ABSsort();
  95. }
  96.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement