/* © MATTO MATTI 2016 http://mattomatti.com/pl/a29 napisane przy użyciu Visual Studio Community 2015 2016-01-22 v 1.0 */ using System; namespace plcode1cs { class Macierz { protected double[,] dane; int Wierszy { get { return dane.GetLength(0); } } int Kolumn { get { return dane.GetLength(1); } } public Macierz(int n, int m) { dane = new double[n, m]; } public Macierz(int n) : this(n, n) { } public void usuńKolumne(int v) { double[,] temp = new double[Wierszy, Kolumn - 1]; for (int x = 0; x < Wierszy; x++) { for (int j = 0, y = 0; j < Kolumn; j++) { if (j != v - 1) { temp[x, y] = dane[x, j]; y++; } } } dane = temp; } public void usuńWiersz(int v) { double[,] temp = new double[Wierszy - 1, Kolumn]; for (int i = 0, x = 0; i < Wierszy; i++) { if (i != v - 1) { for (int y = 0; y < Kolumn; y++) { temp[x, y] = dane[i, y]; } x++; } } dane = temp; } public static Macierz operator *(Macierz m, double a) { Macierz w = new Macierz(m.Wierszy, m.Kolumn); for (int x = 0; x < m.Wierszy; x++) { for (int y = 0; y < m.Kolumn; y++) { w.dane[x, y] = a * m.dane[x, y]; } } return w; } public override string ToString() { string s = ""; for (int x = 0; x < Wierszy; x++) { for (int y = 0; y < Kolumn; y++) { s += String.Format("{0}\t", dane[x, y]); } s += '\n'; } return s; } } class MacierzJednostkowa : Macierz { public MacierzJednostkowa(int n) : base(n) { for (int i = 0; i < n; i++) dane[i, i] = 1; } } class Program { static void Main(string[] args) { Macierz matrix = new MacierzJednostkowa(4); Console.WriteLine("Nowa macierz:\n{0}", matrix); Console.WriteLine("\n\nUsuwamy drugi wiersz macierzy:"); matrix.usuńWiersz(2); Console.WriteLine(matrix); Console.WriteLine("\n\nUsuwamy drugą kolumnę macierzy:"); matrix.usuńKolumne(2); Console.WriteLine(matrix); Console.WriteLine("\n\nMnożymy macierz przez skalar 3:"); matrix = matrix * 3.0; Console.WriteLine(matrix); Console.ReadKey(); } } }