C++中实现矩阵的加法和乘法实例
实现效果图:
实例代码:
#include
using namespace std;
class Matrix
{
int row;//矩阵的行
int col;//矩阵的列
int **a;//保存二维数组的元素
public:
Matrix();//默认构造函数
Matrix(int r, int c);
Matrix(const Matrix &is);//拷贝构造函数
void Madd(const Matrix &is);//矩阵加
Matrix Mmul(const Matrix &is);//矩阵乘
void display();//显示矩阵元素
};
Matrix::Matrix(int r, int c)
{
row = r;
col = c;
a = (int **)malloc(sizeof(int*)*row);
for (int r = 0; r < row; r++)
{
*(a + r) = (int*)malloc(sizeof(int)*col);
}
prin