matrix.h

来自「使用c++实现矩阵的各种运算 」· C头文件 代码 · 共 48 行

H
48
字号
#ifndef HEADER_MATRIX
#define HEADER_MATRIX

//template <typename T>
#include <iostream>
using namespace std;
class Matrix 
{
      private :
              int  nRow ,nCol ;
              
      public  : 
              int **Array ;

              //构造函数
             
              Matrix(int nRow=5 , int nCol=5);
              //矩阵相加
              bool add( Matrix &ma ,Matrix &mb ,Matrix &mc) ;
              //初始化矩阵
              void InitializeMatrix( );//Matrix &ma
 
              //矩阵相减
              void subtraction(Matrix &ma , Matrix &mb ,Matrix &mc) ;
              //矩阵乘法
              void multiplication(Matrix &ma , Matrix &mb ,Matrix &mc) ;
              //获取矩阵的行数 
              int getRow() ;
              //获取矩阵的列数
              int getCol() ;
              //重载符号"<<", 输出矩阵
              friend std::ostream & operator<<(std::ostream &o, Matrix &ma  )//
              {
                   int nRow = ma.getRow() ;
                   int nCol = ma.getCol() ;
	 
                   for(int i = 0 ; i < nRow ; i++)
                   {
                        for(int j = 0; j <nCol ;j++)
                            o << ma.Array[i][j] <<" ";
                        cout<<endl;
                   }
                   return o ;
              }
              //求矩阵均值
              //average(
};
#endif

⌨️ 快捷键说明

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