-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMatrix.cpp
46 lines (39 loc) · 1.13 KB
/
Matrix.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "Matrix.h"
using namespace Bladestick;
Matrix::Matrix(int nRows, int nCols)
{
if (nRows < 1 || nCols < 1)
throw gcnew System::ArgumentException("Êîëè÷åñòâî ñòðîê è êîëè÷åñòâî ñòîëáöîâ äîëæíû áûòü ñòðîãî áîëüøå íóëÿ");
this->nRows = nRows;
this->nCols = nCols;
this->m = gcnew array<double>(nRows * nCols);
}
Matrix ^ Matrix::operator*(Matrix ^ a)
{
if (this->nCols != a->nRows)
throw gcnew System::OperationCanceledException("Êîëè÷åñòâî ñòîëáöîâ ëåâîé ìàòðèöû íå ñîîòâåòñòâóåò êîëè÷åñòâó ñòðîê ïðàâîé ìàòðèöû");
Matrix ^ result = gcnew Matrix(this->nRows, a->nCols);
for (int i = 0; i < this->nRows; ++i)
for (int j = 0; j < a->nCols; ++j)
{
double element = 0;
for (int k = 0; k < this->nCols; ++k)
element += this(i, k) * a(k, j);
result(i, j) = element;
}
return result;
}
double % Matrix::operator()(int row, int col)
{
if (row < 0 || row >= nRows || col < 0 || col >= nCols)
throw gcnew System::ArgumentOutOfRangeException();
return m[nCols * row + col];
}
int Matrix::getRowsCount()
{
return nRows;
}
int Matrix::getColsCount()
{
return nCols;
}