有两个矩阵A和B,均为3行4列,求两个矩阵之和.重载运算符+和-,实现两个矩阵想加和想减
来源:学生作业帮 编辑:大师作文网作业帮 分类:综合作业 时间:2024/11/12 12:52:27
有两个矩阵A和B,均为3行4列,求两个矩阵之和.重载运算符+和-,实现两个矩阵想加和想减
这是一个c++题,
这是一个c++题,
#define maxh 100
#include
using namespace std;
class Matrix { public:
int r, c;
int s[maxh][maxh];
Matrix operator + ( const Matrix &b );
Matrix operator - ( const Matrix &b );
};
Matrix Matrix :: operator + ( const Matrix &b )
{
Matrix res; res.r = r, res.c = c;
for ( int i = 0; i < r; i ++ )
for ( int j = 0; j < c; j ++ )
res.s[i][j] = s[i][j] + b.s[i][j];
return res;
}
Matrix Matrix :: operator - ( const Matrix &b )
{
Matrix res; res.r = r, res.c = c;
for ( int i = 0; i < r; i ++ )
for ( int j = 0; j < c; j ++ )
res.s[i][j] = s[i][j] - b.s[i][j];
return res;
}
Matrix a, b, c;
int main ( )
{
a.r = 4; b.r = 4;
a.c = 3; b.c = 3;
for ( int i = 0; i < a.r; i ++ )
for ( int j = 0; j < a.c; j ++ )
cin >> a.s[i][j];
for ( int i = 0; i < b.r; i ++ )
for ( int j = 0; j < b.c; j ++ )
cin >> b.s[i][j];
c = a + b;
for ( int i = 0; i < c.r; i ++ ) {
for ( int j = 0; j < c.c; j ++ )
cout
#include
using namespace std;
class Matrix { public:
int r, c;
int s[maxh][maxh];
Matrix operator + ( const Matrix &b );
Matrix operator - ( const Matrix &b );
};
Matrix Matrix :: operator + ( const Matrix &b )
{
Matrix res; res.r = r, res.c = c;
for ( int i = 0; i < r; i ++ )
for ( int j = 0; j < c; j ++ )
res.s[i][j] = s[i][j] + b.s[i][j];
return res;
}
Matrix Matrix :: operator - ( const Matrix &b )
{
Matrix res; res.r = r, res.c = c;
for ( int i = 0; i < r; i ++ )
for ( int j = 0; j < c; j ++ )
res.s[i][j] = s[i][j] - b.s[i][j];
return res;
}
Matrix a, b, c;
int main ( )
{
a.r = 4; b.r = 4;
a.c = 3; b.c = 3;
for ( int i = 0; i < a.r; i ++ )
for ( int j = 0; j < a.c; j ++ )
cin >> a.s[i][j];
for ( int i = 0; i < b.r; i ++ )
for ( int j = 0; j < b.c; j ++ )
cin >> b.s[i][j];
c = a + b;
for ( int i = 0; i < c.r; i ++ ) {
for ( int j = 0; j < c.c; j ++ )
cout
有两个矩阵A和B,均为3行4列,求两个矩阵之和.重载运算符+和-,实现两个矩阵想加和想减
有两个矩阵a和b,均为3行4列.求两个矩阵之和.重载运算符“+”,使之能用于矩阵相加.如c=a+b.
有两个矩阵a和b,均为2行3列.求两个矩阵之和.重载运算符“+”,使之能用于矩阵相加.如:c=a+b.
编一个程序,用成员函数重载运算符“+”和“-”,将两个矩阵(这两个矩阵均为2行3列)相加和相减.
用c++编程(1)有2个矩阵A和B(均为2行3列).求2矩阵之和.重载运算符“+”,使之能用于矩阵相加.如:C=A+B.
有两个矩阵,a,b均为2行三列,求矩阵求和,重载运算符“+”,使其能够相加如c=a+b
重载矩阵加法运算.设A,B,C均为m行,n列的矩阵,程序能实现C=A+B的操作.
C语言实现有两个分别是2行3列和3行2列的矩阵,其数据均由键盘输入,这两个矩阵相乘后是一个2*2的矩阵
两个矩阵a 和b 的乘积,结果为c 矩阵,求c 语言程序!
用C语言求两个矩阵相应元素之和(矩阵行和列数使用符合常量).
数学里面的矩阵计算中,A和B为两个矩阵,A:B代表什么运算?
求两个矩阵的和A+B乘积A*B