⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 matrix.cpp

📁 使用c++实现矩阵的各种运算 
💻 CPP
字号:

//#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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -