Advertisement
sdfDFASDFASDF

Untitled

May 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. #pragma once
  2. #include "Matrix.h"
  3. #include <iomanip>
  4.  
  5. template <typename T>
  6. class Filter : public Matrix<T>
  7. {
  8. public:
  9. // Конструкторы ----------------------------------------------------------
  10. Filter(); // По умолчанию
  11. Filter(const int& i_, const int& j_); // Инициализатор (нулевая матрица)
  12. Filter(T** arr_, const int& i_, const int& j_); // Инициализатор
  13. Filter(const Filter<T>& copy); // Копирования
  14.  
  15. // Методы класса ---------------------------------------------------------
  16. // Поворот фильтра на 180
  17. Filter<T> roate_180() const;
  18.  
  19. // Вывод фильтра на консоль в красивом виде
  20. void Out() const;
  21.  
  22. // Перегрузки операторов ------------------------
  23. Filter<T>& operator= (const Filter<T>& copy); // Оператор присваивания
  24.  
  25. // Деструктор ------------------------------------------------------------
  26. ~Filter<T>();
  27. };
  28.  
  29. template <typename T>
  30. Filter<T>::Filter() : Matrix<T>()
  31. {
  32. }
  33.  
  34. template <typename T>
  35. Filter<T>::Filter(const int & i_, const int & j_) : Matrix<T>(i_, j_)
  36. {
  37. }
  38.  
  39. template <typename T>
  40. Filter<T>::Filter(T ** arr_, const int & i_, const int & j_) : Matrix<T>(arr_, i_, j_)
  41. {
  42. }
  43.  
  44. template <typename T>
  45. Filter<T>::Filter(const Filter<T> & copy) : Matrix<T>(copy)
  46. {
  47. }
  48.  
  49. template<typename T>
  50. inline Filter<T> Filter<T>::roate_180() const
  51. {
  52. Filter<T> F(this->n, this->m);
  53. for (int i = this->n-1; i >= 0; i--) {
  54. for (int j = this->m-1; j >= 0; j--) {
  55. F[i][j] = this->arr[this->n-1 - i][this->m-1 - j];
  56. }
  57. }
  58. return F;
  59. }
  60.  
  61. template<typename T>
  62. inline Filter<T>& Filter<T>::operator=(const Filter<T>& copy)
  63. {
  64. if (this == &copy) {
  65. return *this;
  66. }
  67. if ((copy.n > this->n) || (copy.m > this->m)) {
  68. for (int i = 0; i < this->n; i++) {
  69. this->arr[i].reset();
  70. }
  71. this->arr.reset();
  72. this->n = copy.n;
  73. this->m = copy.m;
  74. this->initMat();
  75. }
  76. else {
  77. this->n = copy.n;
  78. this->m = copy.m;
  79. }
  80.  
  81. for (int i = 0; i < this->n; i++) {
  82. for (int j = 0; j < this->m; j++) {
  83. this->arr[i][j] = copy.arr[i][j];
  84. }
  85. }
  86. return *this;
  87. }
  88.  
  89. template <typename T>
  90. Filter<T>::~Filter()
  91. {
  92. }
  93.  
  94. template<typename T>
  95. inline void Filter<T>::Out() const
  96. {
  97. for (int i = 0; i < this->n; i++) {
  98. for (int j = 0; j < this->m; j++) {
  99. std::cout << this->arr[i][j] << " ";
  100. }
  101. std::cout << std::endl;
  102. }
  103. }
  104.  
  105. inline void Filter<int>::Out() const
  106. {
  107. using std::cout;
  108. int max = this->Max();
  109. int k = 2;
  110. while (max > 0) {
  111. k++;
  112. max = max / 10;
  113. }
  114. for (int i = 0; i < this->n; i++) {
  115. for (int j = 0; j < this->m; j++) {
  116. cout << std::setw(k) << this->arr[i][j];
  117. }
  118. cout << std::endl;
  119. }
  120. }
  121.  
  122. inline void Filter<double>::Out() const
  123. {
  124. using std::cout;
  125. int max = (int)this->Max();
  126. int k = 2;
  127. while (max > 0) {
  128. k++;
  129. max = max / 10;
  130. }
  131. for (int i = 0; i < this->n; i++) {
  132. for (int j = 0; j < this->m; j++) {
  133. cout << std::setw(k + 5) << std::setprecision(2) << this->arr[i][j];
  134. }
  135. cout << std::endl;
  136. }
  137. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement