矩阵

来源:互联网 发布:梦幻西游mac右键 编辑:程序博客网 时间:2024/05/21 19:33

矩阵类

接口:int n,m;

          int a[][];

重载运算符:+,-,*,

成员函数:void clear()清空矩阵

const int MAXN=1010;

const int MAXN=1010;

struct  matric

{

int n,m;

int a[MAXN][MAXN];

void clear()

{

n=m=0;

memset(a,0,sizeof(a));

}

Matric operator +(const Matric &b)

const{

Matric tmp;

tmp.n=n;tem.m=m;

for(int i=0;i<n;i++)

for(int j=0;j<m;j++)

tmp.a[i][j]=a[i][j]+b.a[i][j];

return tmp;

}

matric operator-(const Matric &b) const {

Matric tmp;

tmp.n=n;tem.m=m;

for(int i=0;i<n;i++)

for(int j=0;j<m;j++)

tmp.a[I][j]=a[I][j]-b.a[I][j];

return tmp;

}

Matric operator *(const Matric &b) const {

Matric tmp;

tmp.clear();

tmp.n=n;tmp.m=b.m;

for(int i=0;i<n;i++)

for(int j=0;j<b.m;j++)

for(int k=0;k<m;k++)

tmp.a[i][j]+=a[i][j]*b.a[k][j];

return  tmp;

}

};


0 0
原创粉丝点击