Q1. Design a generic matrix multiplier. Here 'generic' means the design should work for any matrix multiplication X-Y = Z, where the matrices X, Y, and Z are of sizes axb, bxc, and axc respectively. Now, pick a, b, c from the last three digits of your roll number. ( If any of the digits is 0, take 3 instead of it; if two digits are Os, then take 3 for the first 0, and 5 for the second 0) For Example, if the last three digits are 123 then a = 1, b = 2, and c = 3; if the last three digits are 204 then a = 2, b = 3, c = 4; f the last three digits are 100 then a = 1, b = 3, c = 5. You are free to choose the elements of the matrices but you need to use those while solving the problem on paper.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Q1. Design a generic matrix multiplier. Here ‘generic’ means the design should work for any
matrix multiplication X∙Y = Z, where the matrices X, Y, and Z are of sizes a×b, b×c, and a×c
respectively. Now, pick a, b, c from the last three digits of your roll number. ( If any of the digits
is 0, take 3 instead of it; if two digits are 0s, then take 3 for the first 0, and 5 for the second 0)
For Example, if the last three digits are 123 then a = 1, b = 2, and c = 3; if the last three digits
are 204 then a = 2, b = 3, c = 4; f the last three digits are 100 then a = 1, b = 3, c = 5.

Q1. Design a generic matrix multiplier. Here 'generic' means the design should work for any
matrix multiplication XY = Z, where the matrices X, Y, and Z are of sizes axb, bxc, and axc
respectively. Now, pick a, b, c from the last three digits of your roll number. ( If any of the digits
is 0, take 3 instead of it; if two digits are Os, then take 3 for the first 0, and 5 for the second 0)
%3D
For Example, if the last three digits are 123 then a =
are 204 then a = 2, b = 3, c = 4; f the last three digits are 100 then a = 1, b = 3, c = 5.
= 1, b = 2, andc = 3; if the last three digits
You are free to choose the elements of the matrices but you need to use those while solving
the problem on paper.
Transcribed Image Text:Q1. Design a generic matrix multiplier. Here 'generic' means the design should work for any matrix multiplication XY = Z, where the matrices X, Y, and Z are of sizes axb, bxc, and axc respectively. Now, pick a, b, c from the last three digits of your roll number. ( If any of the digits is 0, take 3 instead of it; if two digits are Os, then take 3 for the first 0, and 5 for the second 0) %3D For Example, if the last three digits are 123 then a = are 204 then a = 2, b = 3, c = 4; f the last three digits are 100 then a = 1, b = 3, c = 5. = 1, b = 2, andc = 3; if the last three digits You are free to choose the elements of the matrices but you need to use those while solving the problem on paper.
Expert Solution
Step 1

NOTE: Implementation provided in c++ language.

Considerations are made as specified in the question:

  • While implementing the program, the last three digits of the roll number are taken as input from the user.
    • If any digit in the number is '0' then that digit is replaced with '3'.
    • If any two digits in the number are '0' then the first digit is replaced with '3' and the second digit is replaced with '5'.
  • Three digits of roll numbers are used as sizes of the matrix.
    • The first digit of the roll number is 'a'.
    • The second digit is 'b'.
    • The third digit is 'c'.
  • Matrix X with size a*b, Matrix Y with size b*c
    • ex:  a=1 b=2  c=3
    • Data in matrix X with size 1*2,rows =1, columns=2

                                Computer Science homework question answer, step 1, image 1

    • Data in matrix Y with size 2*3, rows=2 columns =3

                                Computer Science homework question answer, step 1, image 2

    • multiplication of matrix X and Y:

                      Computer Science homework question answer, step 1, image 3

               The matrix Z of size 1*3 is generated. Matrix Z size is a*c

 

Step-2
CODE:
 
#include <iostream>
using namespace std;

int main()
{
    int rollnumber;
    int a, b, c;
    int X[10][10], Y[10][10], Z[10][10], i, j, k;
    cout << "Enter last three digits of rollnumber:" << ends;
    cin >> rollnumber;

    if ((c = rollnumber % 10) == 0)
    {
        c = 3;
    }
    rollnumber = rollnumber / 10;
    if ((b = rollnumber % 10) == 0)
    {
        if (c == 3)
        {
            b = 3;
            c = 5;
        }
        else
        {
            b = 3;
        }
    }
    rollnumber = rollnumber / 10;
    if ((a = rollnumber % 10) == 0)
    {
        if (b == 3)
        {
            a = 3;
            b = 5;
        }
        else if (c == 3)
        {
            a = 3;
            c = 5;
        }
        else
        {
            a = 3;
        }
    }

    cout << "a = " << a << " b = " << b << " c = " << c;

    // If column of first matrix in not equal to row of second matrix,
    // ask the user to enter the size of matrix again.

    // Storing elements of first matrix.
    cout << endl
         << "Enter elements of matrix 1:" << endl;
    for (i = 0; i < a; i++)
    {
        for (j = 0; j < b; j++)
        {
            cout << "Enter element X - " << i + 1 << j + 1 << " : ";
            cin >> X[i][j];
        }
    }

    // Storing elements of second matrix.
    cout << endl
         << "Enter elements of matrix 2:" << endl;
    for (i = 0; i < b; i++)
        for (j = 0; j < c; j++)
        {
            cout << "Enter element Y - " << i + 1 << j + 1 << " : ";
            cin >> Y[i][j];
        }

    // Initializing elements of matrix Z to 0.
    for (i = 0; i < a; i++)
        for (j = 0; j < c; j++)
        {
            Z[i][j] = 0;
        }

    // multiplying matrix a and b and storing in array Z.
    for (i = 0; i < a; i++)
    {
        for (j = 0; j < c; j++)
        {
            for (k = 0; k < b; k++)
            {
                Z[i][j] += X[i][k] * Y[k][j];
            }
        }
    }
    cout << endl
         << "X Matrix: " << endl;
    for (i = 0; i < a; i++)
    {
        for (j = 0; j < b; j++)
        {
            cout << " " << X[i][j];
        }
        cout << endl;
    }
    cout << endl
         << "Y Matrix: " << endl;
    for (i = 0; i < b; i++)
    {
        for (j = 0; j < c; j++)
        {
            cout << " " << Y[i][j];
        }
        cout << endl;
    }
    // Displaying the multiplication of two matrix.
    cout << endl
         << "Output Matrix: " << endl;
    for (i = 0; i < a; i++)
    {
        for (j = 0; j < c; j++)
        {
            cout << " " << Z[i][j];
        }
        cout << endl;
    }

    return 0;
}
steps

Step by step

Solved in 3 steps with 4 images

Blurred answer
Knowledge Booster
Heapsort
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
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education