#include "intmatrix.h" #include #include #include intmatrix::intmatrix(int rs, int cs) { rows = rs; cols = cs; data = new int [rs*cs]; } intmatrix::~intmatrix() { delete [] data; data = NULL; } int intmatrix::position(int r, int c) { assert(r >= 0); assert(r < rows); assert(c >= 0); assert(c < cols); return r * cols + c; } void intmatrix::fill(int val) { for (int r = 0; r < rows; r += 1) for (int c = 0; c < cols; c += 1) data[position(r, c)] = val; } void intmatrix::set(int r, int c, int val) { data[position(r, c)] = val; } int intmatrix::get(int r, int c) { return data[position(r, c)]; } int intmatrix::get_rows() { return rows; } int intmatrix::get_columns() { return cols; } void intmatrix::print() { for (int r = 0; r < rows; r += 1) { for (int c = 0; c < cols; c += 1) cout << setw(4) << get(r, c); cout << "\n"; } }