矩阵类的设计,用C++,要求:定义矩阵类,包含行、列和矩阵数据元素;

来源:百度知道 编辑:UC知道 时间:2024/06/25 03:12:11
最好是用到构造函数,重载函数等等,一定要有说明。很着急,明天交!~!~1
要求至少设计以下各功能模块:
 输入矩阵
 输出矩阵
 矩阵的加法
 矩阵的乘法 \
只有一天的时间了!~~!

我没有重载函数,只重载了运算符,你看看行不行。

这是头文件:

#ifndef MATRIX_H
#define MATRIX_H
#include <iostream>
using std::cout;
using std::endl;

class Matrix{
public:
Matrix():row(0),column(0),m(0){}
Matrix(const Matrix& ma);
~Matrix();
void setMatrix(int r,int c,double **ma);
int getRow(){return row;}
int getColumn(){return column;}
void display();
Matrix& operator=(const Matrix& ma);
Matrix operator+(const Matrix& ma)const;
Matrix operator-(const Matrix& ma)const;
Matrix operator*(const Matrix& ma)const;
private:
int row;
int column;
double** m;
};

Matrix::Matrix(const Matrix &ma){
this->row=ma.row;
this->column=ma.column;
m=new double *[row];
for(int i=0;i<row;i++)
m[i]=new double[column];
for(int i=0;i<row;i++)
for(int j=0;j<column;j++)
m[i][j]=ma.m[i][j];
}