Tec4Gen

Untitled

Dec 18th, 2019
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.01 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Threading.Tasks;
  7.  
  8.  
  9. namespace MyProgram
  10. {
  11. class Matrix
  12. {
  13. double[][] doubleArray;//создаем двумерный массив
  14. int n;
  15. int m;
  16. int count;
  17. public Matrix(int n, int m)//конструктор принимает в качестве параметров количество строк и колонок
  18. {
  19. this.n = n;
  20. this.m = m;
  21. double[][] doubleArray = new double[n][];
  22. for (int i = 0; i < n; i++)
  23. {
  24. doubleArray[i] = new double[m];
  25. }
  26. }
  27.  
  28.  
  29. public Matrix(Matrix doubleArray) //конструктор 2
  30. {
  31. double[] array = new double[doubleArray.doubleArray.Length];
  32. Array.Copy(doubleArray.doubleArray, array, doubleArray.doubleArray.Length);
  33. }
  34.  
  35. public Matrix()
  36. { }
  37. public void fillArray()//заполняем массив с клавиатуры
  38. {
  39. doubleArray = new double[n][];
  40. for (int i = 0; i < n; i++)
  41. {
  42. doubleArray[i] = new double[m];
  43. for (int j = 0; j < doubleArray[i].Length; j++)
  44. {
  45. Console.Write("Enter element {0},{1} : ", i, j);
  46. doubleArray[i][j] = Convert.ToDouble(Console.ReadLine());
  47. }
  48. }
  49. }
  50. public void printArray()//вывод массива на консоль
  51. {
  52. for (int i = 0; i < n; i++)
  53. {
  54. for (int j = 0; j < m; j++)
  55. {
  56. Console.Write(doubleArray[i][j] + " ");
  57. }
  58. Console.WriteLine();
  59. }
  60. }
  61. public void sortArray()//сортируем массив
  62. {
  63.  
  64. // var ArrSort = doubleArray.OrderByDescending(n => doubleArray[n][m] > doubleArray[n][m+1]);
  65. for (int i = 0; i < n; i++)
  66. {
  67. Array.Sort(doubleArray[i]);//сортировка массива по возрастанию
  68. Array.Reverse(doubleArray[i]);//изменяет порядок элементов массива на противоположные))
  69. }
  70.  
  71.  
  72. }
  73. public int Count//возвращаем количество элементов массива
  74. {
  75. get { return n * m; }
  76.  
  77. }
  78. public double Scal//увеличение всех элементов на скаляр
  79. {
  80.  
  81. set
  82. {
  83. for (int i = 0; i < doubleArray.Length; i++)
  84. {
  85. for (int j = i; j < doubleArray[i].Length; j++)
  86. {
  87. doubleArray[i][j] = i*j;
  88. }
  89. }
  90.  
  91. }
  92. }
  93. public double this[int n, int m]
  94. {
  95. get
  96. {
  97. try
  98. {
  99. return doubleArray[n][m];
  100. }
  101. catch
  102. {
  103.  
  104. Console.WriteLine("Error");
  105. return 0;
  106. }
  107.  
  108. }
  109.  
  110. }
  111. //перегрузка операторов
  112. public static Matrix operator ++(Matrix arr)
  113. {
  114. Matrix temp = new Matrix (arr);
  115. for (int i = 0; i<temp.n;i++)
  116. {
  117. for (int j = 0; j <temp. m; j++)
  118. {
  119. temp.doubleArray[i][j] = arr.doubleArray[i][j] + 1;
  120. }
  121. }
  122.  
  123. return temp;
  124. }
  125. public static Matrix operator --(Matrix arr)
  126. {
  127. Matrix temp = new Matrix(arr);
  128. for (int i = 0; i < temp.n; i++)
  129. {
  130. for (int j = 0; j < temp.m; j++)
  131. {
  132. temp.doubleArray[i][j] = arr.doubleArray[i][j] -1;
  133. }
  134. }
  135.  
  136. return temp;
  137. }
  138. public static bool operator true(Matrix arr) //перегрузка константы true
  139. {
  140.  
  141. for (int i = 0; i < arr.n; i++)
  142. {
  143. for (int j = 0; j < arr.m - 1; j++)
  144. {
  145. if (arr.doubleArray[i][j] > arr.doubleArray[i][j + 1])
  146. {
  147. return false;
  148. }
  149. }
  150. }
  151. return true;
  152. }
  153. public static bool operator false(Matrix arr) //перегрузка константы false
  154. {
  155. for (int i = 0; i < arr.n; i++)
  156. {
  157. for (int j = 0; j < arr.m - 1; j++)
  158. {
  159. if (arr.doubleArray[i][j] < arr.doubleArray[i][j + 1])
  160. {
  161. return true;
  162. }
  163. }
  164. }
  165. return true;
  166. }
  167. }
  168. }
Advertisement
Add Comment
Please, Sign In to add comment