Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- using System.Threading.Tasks;
- namespace MyProgram
- {
- class Matrix
- {
- double[][] doubleArray;//создаем двумерный массив
- int n;
- int m;
- int count;
- public Matrix(int n, int m)//конструктор принимает в качестве параметров количество строк и колонок
- {
- this.n = n;
- this.m = m;
- double[][] doubleArray = new double[n][];
- for (int i = 0; i < n; i++)
- {
- doubleArray[i] = new double[m];
- }
- }
- public Matrix(Matrix doubleArray) //конструктор 2
- {
- double[] array = new double[doubleArray.doubleArray.Length];
- Array.Copy(doubleArray.doubleArray, array, doubleArray.doubleArray.Length);
- }
- public Matrix()
- { }
- public void fillArray()//заполняем массив с клавиатуры
- {
- doubleArray = new double[n][];
- for (int i = 0; i < n; i++)
- {
- doubleArray[i] = new double[m];
- for (int j = 0; j < doubleArray[i].Length; j++)
- {
- Console.Write("Enter element {0},{1} : ", i, j);
- doubleArray[i][j] = Convert.ToDouble(Console.ReadLine());
- }
- }
- }
- public void printArray()//вывод массива на консоль
- {
- for (int i = 0; i < n; i++)
- {
- for (int j = 0; j < m; j++)
- {
- Console.Write(doubleArray[i][j] + " ");
- }
- Console.WriteLine();
- }
- }
- public void sortArray()//сортируем массив
- {
- // var ArrSort = doubleArray.OrderByDescending(n => doubleArray[n][m] > doubleArray[n][m+1]);
- for (int i = 0; i < n; i++)
- {
- Array.Sort(doubleArray[i]);//сортировка массива по возрастанию
- Array.Reverse(doubleArray[i]);//изменяет порядок элементов массива на противоположные))
- }
- }
- public int Count//возвращаем количество элементов массива
- {
- get { return n * m; }
- }
- public double Scal//увеличение всех элементов на скаляр
- {
- set
- {
- for (int i = 0; i < doubleArray.Length; i++)
- {
- for (int j = i; j < doubleArray[i].Length; j++)
- {
- doubleArray[i][j] = i*j;
- }
- }
- }
- }
- public double this[int n, int m]
- {
- get
- {
- try
- {
- return doubleArray[n][m];
- }
- catch
- {
- Console.WriteLine("Error");
- return 0;
- }
- }
- }
- //перегрузка операторов
- public static Matrix operator ++(Matrix arr)
- {
- Matrix temp = new Matrix (arr);
- for (int i = 0; i<temp.n;i++)
- {
- for (int j = 0; j <temp. m; j++)
- {
- temp.doubleArray[i][j] = arr.doubleArray[i][j] + 1;
- }
- }
- return temp;
- }
- public static Matrix operator --(Matrix arr)
- {
- Matrix temp = new Matrix(arr);
- for (int i = 0; i < temp.n; i++)
- {
- for (int j = 0; j < temp.m; j++)
- {
- temp.doubleArray[i][j] = arr.doubleArray[i][j] -1;
- }
- }
- return temp;
- }
- public static bool operator true(Matrix arr) //перегрузка константы true
- {
- for (int i = 0; i < arr.n; i++)
- {
- for (int j = 0; j < arr.m - 1; j++)
- {
- if (arr.doubleArray[i][j] > arr.doubleArray[i][j + 1])
- {
- return false;
- }
- }
- }
- return true;
- }
- public static bool operator false(Matrix arr) //перегрузка константы false
- {
- for (int i = 0; i < arr.n; i++)
- {
- for (int j = 0; j < arr.m - 1; j++)
- {
- if (arr.doubleArray[i][j] < arr.doubleArray[i][j + 1])
- {
- return true;
- }
- }
- }
- return true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment