第10题
class Matrix {
public:
Matrix(int row,int col); // 构造一个具有row 行col 列的矩阵
~Matrix() {delete []mem;} // 析构函数
friend bool Multiply(Matrix &m1, Matrix &m2, Matrix &m3);
// 定义Multiply() 为友元函数,该函数把m1×m2的值赋给m3
// 其他成员函数从略
private:
int *mem; // 动态申请矩阵空间
const int rows,cols; // 矩阵的行数和列数
};
Matrix::Matrix(int row,int col):rows(row),cols(col)
{
mem = new int[row*col];
}
bool Multiply(Matrix &m1, Matrix &m2, Matrix &m3)
{
// 确定矩阵是否能够进行相乘
if(m1.rows != m3.rows ||m2.cols != m3.cols || m1.cols != m2.rows) return false;
// 定义sum变量,用于计算乘积矩阵m3中每个元素的值
int sum;
// 请在下面编写剩余部分
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!