Enter values for array M: -9 14 1 -5 3 7 Enter values 1 2 for array N : Matrix M x N is : 33 38 -18 34 -14 24 The sum of elements in MN is : 97
A matrix is an array of numbers of size m by n (i.e., m x n). When we multiply 2 matrices, we multiply the matching numbers, then sum them up. Multiplying a matrix of size m x n with another matrix of size n x q will result in a matrix of size m x q. An example is shown in Figure 1: [ ? ? ? ? ? ? ] x [ ? ? ? ? ] = [ ?? +?? ?? + ?? ?? + ?? ?? + ?? ?? + ?? ?? + ?? ] Matrix 3 x 2 Matrix 2 x 2 Matrix 3 x 2 Figure 1: Multiplication of Matrix 3 x 2 and 2 x 2 Write a C++ program that multiplies 2 matrices and return the sum of the transposed matrix. Your program shall include the following: a) Define two 2 dimensional arrays, M and N that each represents a matrix of size 3 x 2 and a matrix of size 2 x 2. Request the user to enter the values for the 2 arrays using advanced pointer notations (refer to your slides for the list of array pointer notations). b) Create a function named multMatrix() that passes as arguments, the values of array M and N, multiplies them and store the results in a new matrix MN. Use pointer notations to multiply your arrays. Display your multiplied arrays. c) Create a function named calcTotal() that passes as argument, the values of array MN, sum up all its elements and return the total value from the function. Use advanced pointer notations to perform your summation. Display your result in main(). The basic program and function stubs are given below as a guideline. #include using namespace std; //declare rows and columns sizes //declare all empty arrays here as global void multMatrix(); //complete your prototype int calcTotal();//complete your prototype int main() { //get user input for array values using nested loop //call multMatrix() : pass arrays to multiply Department of Computer Science, KICT 23 DEC 2021 2 //call calcTotal(): pass multiplied array //display result of calcTotal } void multMatrix()//pass 2 arrays { //create if-else condition in nested loop to determine index position //multiply arrays //display array } int calcTotal()//pass multiplied array { //more codes here return sum; } Sample Output
Trending now
This is a popular solution!
Step by step
Solved in 8 steps with 6 images