Skip to content

Commit

Permalink
Update matrix.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
manika88 authored Dec 31, 2024
1 parent c154de8 commit 94f56d2
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions task1/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,45 +4,57 @@

Matrix::Matrix(int numRows, int numCols)
{
// your implementation here
Reset(numRows, numCols);
}

void Matrix::Reset(int numRows, int numCols)
{
// your implementation here
if (numRows == 0 || numCols == 0)
{
row = col = 0;
}
}

int& Matrix::At(int row, int col)
{
// your implementation here
if (row < 0 || row >=numRows || col < 0 || col >= numCols)
{
throw std::out_of_range;
}
}

const int& Matrix::At(int row, int col) const
{
// your implementation here
if (row < 0 || row >=numRows || col < 0 || col >= numCols)
{
throw std::out_of_range;
}
}

int Matrix::GetRows() const
{
// your implementation here
return numRows;
}

int Matrix::GetCols() const
{
// your implementation here
return numCols;
}

bool Matrix::operator==(const Matrix& m2)
{
// your implementation here
return == m2.numRows && cols == m2.numCols && data == m2.data;
}

bool Matrix::operator!=(const Matrix& m2)
{
// your implementation here
return !(*this == m2);
}

Matrix Matrix::operator+(const Matrix& m2)
{
// your implementation here
if (row != m2.numRows || col != m2.numCols)
{
throw std::invalid_argument;
}
}

0 comments on commit 94f56d2

Please sign in to comment.