【正确答案】#include<iostream.h>
class Mx
{public:
Mx();
friend Mx operator+(Mx&,Mx&);
void input();
void show();
private:
int m[2][3];
};
Mx::Mx()
{for(int i=0;i<2;i++)
for(int j=0;j<3;j++)
m[i][j]=0;
}
Mx operator+(Mx&a,Mx&b)
{Mx c;
for(int i=0;i<2;i++)
for(int j=0;j<3;j++)
c.m[i][j]=a.m[i][j]+b.m[i][j];
return c;
}
void Mx::input()
{cout<<"输入矩阵的值:"<<endl;
for(int i=0;i<2;i++)
for(int j=0;j<3;j++)
cin>>m[i][j];
}
void Mx::show()
{for(int i=0;i<2;i++)
{for(int j=0;j<3;j++)
cout<<m[i][j]<<"";
cout<<endl:
}
}
void main()
{ Mx a,b,c;
a.input();
b.input();
tout<<endl<<"矩阵a:"<<endl;
a.sbow();
cout<<endl<<"矩阵b:"<<endl;
b.show();
c=a+b;
cout<<endl<<"矩阵c=矩阵a+矩阵b"<<endl;
c.show();
}
【答案解析】