Write a friend function multElements that takes two Matrix input parameters, checks to see if they are the same size (if not, displays a message stating this) and fills a Matrix output parameter with the products of corresponding elements of the two input parameters.


const int MAX_ROWS = 10;
const int MAX_COLS = 10;

class Matrix {
public:
Matrix() {}
private:
int rows;
int cols;
int mat[MAX_ROWS][MAX_COLS];
};



// #4
void multElements( Matrix& result, const Matrix& m1, const Matrix& m2 )
{
if (m1.rows == m2.rows && m1.cols == m2.cols)
for (int i = 0; i < m1.rows; ++i)
for (int j = 0; j < m1.cols; ++j)
result.mat[i][j] = m1.mat[i][j] * m2.mat[i][j];
else
cout << "Error in multElements: Matrix dimensions do not match."
<< endl;
}

Computer Science & Information Technology

You might also like to view...

A recursive solution is usually much harder to code than the iterative solution.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology

A dual-alternative selection structure is also known as a(n) __________ structure.

Fill in the blank(s) with correct word

Computer Science & Information Technology

Write an iterative method to print a string backwards.

What will be an ideal response?

Computer Science & Information Technology

A(n) _______________________________ is a set of principles to guide a support worker's professional behavior.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology