matrix.cpp

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

CPP
66
字号

//#include <iostream>
//using namespace std ;
#include "Matrix.h" 

int Matrix::getRow()
{
    return this->nRow ;
}

int Matrix::getCol()
{
    return this->nCol ;
}

Matrix::Matrix(int nRow=5, int nCol=5)
{
    this->nRow = nRow ;
    this->nCol = nCol ;
}

void Matrix::InitializeMatrix() 
{
     int nRow = this->getRow() ;
     int nCol = this->getCol() ;
     this->Array = new int *[nRow];
	 int i,j;
	 for(i = 0; i < nRow; i++)
		 this->Array[i] = new int [nCol] ;
     cout<<"input elements of Array"<<endl;

     for(i = 0 ; i < nRow ; i++)
        for(j = 0; j <nCol ;j++)
        cin >>this->Array[i][j] ;
           
}


bool Matrix::add(Matrix &ma ,Matrix &mb ,Matrix &mc) 
{
     if(ma.getRow()!=mb.getRow() || ma.getCol() !=mb.getCol()) 
           return false;
     int nRow = ma.getRow() ;
     int nCol = ma.getCol() ;
     for(int i = 0;i < nRow ; i++)
        for(int j = 0; j < nCol ; j++)
            mc.Array[i][j] = ma.Array[i][j] + mb.Array[i][j] ;
     return true ;
}
















⌨️ 快捷键说明

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