Closed alexey-malov closed 6 years ago
void MatrixByScalar(Matrix2D& matrix, const double scalar)
{
for_each(matrix.values.begin(), matrix.values.end(), [scalar](vector<double>& row)
{
for_each(row.begin(), row.end(), [scalar](double& element)
{
element *= scalar;
});
});
}
[x] Нет глагола в имени функции.
[x] вместо vector
void SetMinorMatrix(Matrix2D& matrix, Matrix2D& minorMatrix)
{
for (unsigned int i = 0; i < matrix.rowsCount; ++i)
{
vector<double> subRow;
for (unsigned int j = 0; j < matrix.colsCount; ++j)
{
subRow.push_back(GetMinorOfMatrix(matrix, i, j));
}
minorMatrix.values.push_back(subRow);
}
}
[x] объекты следует передавать по константной ссылке, если функция не модифицирует их состояние. Примитивные объекты передавать по константной ссылке выгоды нет, лучше по значению
[x] Вместо out-параметра (который функция забыла проинициализировать) лучше использовать возвращаемое значение
void Print2DVector(Matrix2D& matrix)
{
for_each(matrix.values.begin(), matrix.values.end(), [](vector<double>& row)
{
for_each(row.begin(), row.end(), [](double& element)
{
cout << element << setprecision(3) << ' ';
});
cout << "\n";
});
}
[x] Что за 2D Vector?
[x] Внутренний for_each - фактически - copy. Внешний можно заменить на range-based-for
void SetSubMatrix(Matrix2D& matrix, Matrix2D& subMatrix, unsigned int cutRow, unsigned int cutColumn)
for (const MatrixRow row : matrix.values)
{
copy(row.begin(), row.end(), ostream_iterator<double>(cout, " "));
cout << "\n";
}
[x] мы получаем инвертированную матрицу только на последнем шаге
[x] definer -> determinant
[x] В какой момент у матрицы появляется определитель? Он не должен являться частью матрицы, покуда клиенты могут беспрепятственно модифицировать её элементы, делая определитель неактуальным