matdemo.cpp

来自「C++&datastructure书籍源码,以前外教提供现在与大家共享」· C++ 代码 · 共 37 行

CPP
37
字号
#include <iostream>#include <string>#include <iomanip>     // for setwusing namespace std;#include "tmatrix.h"// demonstrate class tmatrixtemplate <class T>void Print(const tmatrix<T>& mat){    int j,k;    int rows = mat.numrows(), cols = mat.numcols();    for(j=0; j < rows; j++)    {   for(k=0; k < cols; k++)        {   cout << setw(4) << mat[j][k];        }        cout << endl;    }}int main(){    int rows, cols,j,k;    cout << "row col dimensions: ";    cin >> rows >> cols;        tmatrix<int> mat(rows,cols);    for(j=0; j < rows; j++)              // fill matrix    {   for(k=0; k < cols; k++)        {   mat[j][k] = (j+1)*(k+1);        }    }    Print(mat);    return 0;    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?