#include #include #include "matrix.h" Matrix::Matrix(int nrows, int ncols) { if (_values = (ValType *) new ValType[nrows * ncols]) { _nrows = nrows; _ncols = ncols; } } Matrix::~Matrix() { delete [] _values; } int Matrix::num_rows() { return _nrows; } int Matrix::num_cols() { return _ncols; } ValType & Matrix::operator()(int i, int j) { return _values[j + i * _ncols]; } ostream & operator << (ostream & os, Matrix & mat) { for (int i = 0; i < mat.num_rows(); i++) { for (int j = 0; j < mat.num_cols(); j++) os << mat(i, j) << '\t'; os << endl; } return os; }