//matrix.cpp #include "matrix.h" #include using namespace std; Matrix* MatrixCreate(int nrows, int ncols) { Matrix *mat; if (mat = new Matrix) if (mat->values = new ValType[nrows * ncols]) { mat->nrows = nrows; mat->ncols = ncols; return mat; } else delete mat; return 0; } void MatrixSetValue(Matrix *mat, int i, int j, ValType value) { mat->values[j + i * mat->ncols] = value; } ValType MatrixGetValue(Matrix *mat, int i, int j) { return mat->values[j + i * mat->ncols]; } void MatrixPrint(Matrix *mat) { int i,j; for (i = 0; i < mat->nrows; i++) { for (j = 0; j < mat->ncols; j++) cout << MatrixGetValue(mat, i, j) << '\t'; cout << endl; } } void MatrixDestroy(Matrix *mat) { delete [] mat->values; delete mat; }