using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Matrix {
protected int row, column;
protected int[,] ARRAY;
public int ROW {
get { return row; }
set { row = value; }
}
public int COLUMN {
get { return column; }
set { column = value; }
}
public Matrix() {
}
public Matrix(int row, int column) {
this.row = ROW;
this.column = COLUMN;
ARRAY = new int[this.COLUMN, this.ROW];
}
public void EnterMatrix() {
Console.WriteLine("enter the numbers of matrix columns: ");
COLUMN = int.Parse(Console.ReadLine());
Console.WriteLine("enter the numbers of matrix rows: ");
ROW = int.Parse(Console.ReadLine());
ARRAY = new int[COLUMN, ROW];
for (int col = 0; col < COLUMN; col++) {
for (int row = 0; row < ROW; row++) {
Console.WriteLine("enter the elements of matrix cell[" + (col + 1) + ":" + (row + 1) + "]: ");
ARRAY[col, row] = int.Parse(Console.ReadLine());
}
}
}
public void Display() {
for (int col = 0; col < COLUMN; col++) {
Console.WriteLine("\n");
for (int row = 0; row < ROW; row++) {
Console.Write("{0}\t", ARRAY[col, row]);
}
}
Console.WriteLine();
}
public void ARRAYxARRAY(int[,] firstMatrix, int[,] secondMatrix, int[,] mult,
int rowFirst, int columnFirst,
int rowSecond, int columnSecond) {
for (int i = 0; i < rowFirst; i++) {
for (int j = 0; j < columnSecond; j++) {
mult[i, j] = 0;
}
}
for (int i = 0; i < rowFirst; i++) {
for (int j = 0; j < columnSecond; j++) {
for (int k = 0; k < columnFirst; k++) {
mult[i, j] += firstMatrix[i, k];
}
}
}
}
public void ARRAYxARRAY(Matrix Matrix, int a) {
for (int col = 0; col < COLUMN; col++) {
for (int row = 0; row < ROW; row++) {
ARRAY[col, row] = a * Matrix.ARRAY[col, row];
}
}
}
public void ARRAYxARRAY(int a, Matrix Matrix) {
for (int col = 0; col < COLUMN; col++) {
for (int row = 0; row < ROW; row++) {
ARRAY[col, row] = a * Matrix.ARRAY[col, row];
}
}
}
public void ARRAYxARRAY(Matrix fMatrix, Matrix sMatrix) {
for (int col = 0; col < COLUMN; col++) {
for (int row = 0; row < ROW; row++) {
ARRAY[col, row] += fMatrix.ARRAY[col, row] * sMatrix.ARRAY[col, row];
}
}
}
public void ARRAYxARRAY(Matrix Matrix, Vector Vector) {
for (int col = 0; col < COLUMN; col++) {
for (int row = 0; row < ROW; row++) {
ARRAY[col, row] += Matrix.ARRAY[col, row] * Vector.ARRAY[col, row];
}
}
}
~Matrix() {
Console.WriteLine("Matrix has been denied.");
}
}
class Vector : Matrix {
public Vector() {
}
public Vector(int row, int column) {
this.row = ROW;
this.column = COLUMN;
ARRAY = new int[this.COLUMN, this.ROW];
}
public void EnterVector() {
Console.WriteLine("Choose type of vector: " +
"\nvector-row= [1]" +
"\nvector-col= [2]");
int variant = int.Parse(Console.ReadLine());
if (variant == 1) {
COLUMN = 1;
Console.WriteLine("enter the number of vector elements: ");
ROW = int.Parse(Console.ReadLine());
}
else if (variant == 2) {
ROW = 1;
Console.WriteLine("enter the numbers of vector elements: ");
COLUMN = int.Parse(Console.ReadLine());
}
ARRAY = new int[COLUMN, ROW];
for (int col = 0; col < COLUMN; col++) {
for (int row = 0; row < ROW; row++) {
Console.WriteLine("enter the elements of matrix cell[" + (col + 1) + ":" + (row + 1) + "]: ");
ARRAY[col, row] = int.Parse(Console.ReadLine());
}
}
}
public void ARRAYxARRAY(Vector fVector, Vector sVector) {
for (int col = 0; col < COLUMN; col++) {
for (int row = 0; row < ROW; row++) {
ARRAY[col, row] += fVector.ARRAY[col, row] * sVector.ARRAY[col, row];
}
}
}
~Vector() {
Console.WriteLine("Vector has been denied.");
}
}
class Test {
static void Main() {
Matrix MATRIX = new Matrix();
MATRIX.EnterMatrix();
Console.WriteLine("The matrix is: ");
MATRIX.Display();
Console.WriteLine("\n");
Vector VECTOR = new Vector();
VECTOR.EnterVector();
Console.WriteLine("The matrix is: ");
VECTOR.Display();
while (true) {
Console.Write("Select anoperation:\n"
+ "\t1. matrix * matrix;\n"
+ "\t2. matrix * vector;\n"
+ "\t3. number * matrix;\n"
+ "\t4. vector * matrix;\n"
+ "\t5. vector * vector;\n"
+ "\t6. number * vectir;\n");
int choice = int.Parse(Console.ReadLine());
switch (choice) {
case 1: Matrix MATRIXbyMATRIX = new Matrix();
MATRIXbyMATRIX.ARRAYxARRAY(MATRIX, MATRIX);
MATRIXbyMATRIX.Display();
break;
case 2:
Matrix MATRIXbyVECTOR = new Matrix();
MATRIXbyVECTOR.ARRAYxARRAY(MATRIX, VECTOR);
MATRIXbyVECTOR.Display();
break;
case 3:
Matrix NUMBERbyMATRIX = new Matrix();
Console.Write("enter the number to multiply by: ");
int numb1 = int.Parse(Console.ReadLine());
NUMBERbyMATRIX.ARRAYxARRAY(numb1, MATRIX);
NUMBERbyMATRIX.Display();
break;
case 4:
Matrix VECTORbyMATRIX = new Matrix();
VECTORbyMATRIX.ARRAYxARRAY(VECTOR, MATRIX);
VECTORbyMATRIX.Display();
break;
case 5:
Matrix VECTORbyVECTOR = new Matrix();
VECTORbyVECTOR.ARRAYxARRAY(VECTOR, VECTOR);
VECTORbyVECTOR.Display();
break;
case 6:
Matrix NUMBERbyVECTOR = new Matrix();
Console.Write("enter the number to multiply by: ");
int numb2 = int.Parse(Console.ReadLine());
NUMBERbyVECTOR.ARRAYxARRAY(numb2, VECTOR);
NUMBERbyVECTOR.Display();
break;
default:
return;
}
}
}
}