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

Programming Logic & Design Comprehensive
9th Edition
ISBN:9781337669405
Author:FARRELL
Publisher:FARRELL
Chapter6: Arrays
Section: Chapter Questions
Problem 16RQ
icon
Related questions
Question

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 

Enter values for array M:
-9 14
1 -5
3 7
Enter values
1 2
3 4
for array N :
Matrix M x N is :
38
-14 -18
34
33
24
The sum of elements in MN is :
97
Transcribed Image Text:Enter values for array M: -9 14 1 -5 3 7 Enter values 1 2 3 4 for array N : Matrix M x N is : 38 -14 -18 34 33 24 The sum of elements in MN is : 97
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 8 steps with 6 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage