1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Advocard [28]
3 years ago
13

g For this project you are required to perform Matrix operations (Addition, Subtraction and Multiplication). For each of the ope

rations mentioned above you have to make a function in addition to two other functions for ‘Inputting’ and ‘Displaying’ the Matrices in Row Order (rows are populated left to right, in sequence). In total there will be 5 functions: 3 for the operations and 2 functions for inputting and displaying the data.
Engineering
1 answer:
Kruka [31]3 years ago
5 0

Answer:

C++ code is explained below

Explanation:

#include<iostream>

using namespace std;

//Function Declarations

void add();

void sub();

void mul();

//Main Code Displays Menu And Take User Input

int main()

{

  int choice;

  cout << "\nMenu";

  cout << "\nChoice 1:addition";

  cout << "\nChoice 2:subtraction";

  cout << "\nChoice 3:multiplication";

  cout << "\nChoice 0:exit";

 

  cout << "\n\nEnter your choice: ";

 

  cin >> choice;

 

  cout << "\n";

 

  switch(choice)

  {

      case 1: add();

              break;

             

      case 2: sub();

              break;

             

      case 3: mul();

              break;

     

      case 0: cout << "Exited";

              exit(1);

     

      default: cout << "Invalid";      

  }

  main();  

}

//Addition Of Matrix

void add()

{

  int rows1,cols1,i,j,rows2,cols2;

 

  cout << "\nmatrix1 # of rows: ";

  cin >> rows1;

 

  cout << "\nmatrix1 # of columns: ";

  cin >> cols1;

 

   int m1[rows1][cols1];

 

  //Taking First Matrix

  for(i=0;i<rows1;i++)

      for(j=0;j<cols1;j++)

      {

          cout << "\nEnter element (" << i << "," << j << "): ";

          cin >> m1[i][j];

          cout << "\n";

      }

  //Printing 1st Matrix

  for(i=0;i<rows1;i++)

  {

      for(j=0;j<cols1;j++)

          cout << m1[i][j] << " ";

      cout << "\n";

  }

     

  cout << "\nmatrix2 # of rows: ";

  cin >> rows2;

 

  cout << "\nmatrix2 # of columns: ";

  cin >> cols2;

 

  int m2[rows2][cols2];

  //Taking Second Matrix

  for(i=0;i<rows2;i++)

      for(j=0;j<cols2;j++)

      {

          cout << "\nEnter element (" << i << "," << j << "): ";

          cin >> m2[i][j];

          cout << "\n";

      }

  //Displaying second Matrix

  cout << "\n";

  for(i=0;i<rows2;i++)

  {

      for(j=0;j<cols2;j++)

          cout << m2[i][j] << " ";

      cout << "\n";

  }

  //Displaying Sum of m1 & m2

  if(rows1 == rows2 && cols1 == cols2)

  {

      cout << "\n";

      for(i=0;i<rows1;i++)

      {

          for(j=0;j<cols1;j++)

              cout << m1[i][j]+m2[i][j] << " ";

          cout << "\n";  

      }

  }

  else

      cout << "operation is not supported";

     

  main();

 

}

void sub()

{

  int rows1,cols1,i,j,k,rows2,cols2;

  cout << "\nmatrix1 # of rows: ";

  cin >> rows1;

 

  cout << "\nmatrix1 # of columns: ";

  cin >> cols1;

 

   int m1[rows1][cols1];

 

  for(i=0;i<rows1;i++)

      for(j=0;j<cols1;j++)

      {

          cout << "\nEnter element (" << i << "," << j << "): ";

          cin >> m1[i][j];

          cout << "\n";

      }

 

  for(i=0;i<rows1;i++)

  {

      for(j=0;j<cols1;j++)

          cout << m1[i][j] << " ";

      cout << "\n";

  }

     

  cout << "\nmatrix2 # of rows: ";

  cin >> rows2;

 

  cout << "\nmatrix2 # of columns: ";

  cin >> cols2;

 

  int m2[rows2][cols2];

 

  for(i=0;i<rows2;i++)

      for(j=0;j<cols2;j++)

      {

          cout << "\nEnter element (" << i << "," << j << "): ";

          cin >> m2[i][j];

          cout << "\n";

      }

 

  for(i=0;i<rows2;i++)

  {

      for(j=0;j<cols2;j++)

          cout << m1[i][j] << " ";

      cout << "\n";

  }

  cout << "\n";

  //Displaying Subtraction of m1 & m2

  if(rows1 == rows2 && cols1 == cols2)

  {

      for(i=0;i<rows1;i++)

      {

          for(j=0;j<cols1;j++)

              cout << m1[i][j]-m2[i][j] << " ";

          cout << "\n";  

      }

  }

  else

      cout << "operation is not supported";

     

  main();

 

}

void mul()

{

  int rows1,cols1,i,j,k,rows2,cols2,mul[10][10];

  cout << "\nmatrix1 # of rows: ";

  cin >> rows1;

 

  cout << "\nmatrix1 # of columns: ";

  cin >> cols1;

 

   int m1[rows1][cols1];

 

  for(i=0;i<rows1;i++)

      for(j=0;j<cols1;j++)

      {

          cout << "\nEnter element (" << i << "," << j << "): ";

          cin >> m1[i][j];

          cout << "\n";

      }

  cout << "\n";

  for(i=0;i<rows1;i++)

  {

      for(j=0;j<cols1;j++)

          cout << m1[i][j] << " ";

      cout << "\n";

  }

     

  cout << "\nmatrix2 # of rows: ";

  cin >> rows2;

 

  cout << "\nmatrix2 # of columns: ";

  cin >> cols2;

 

  int m2[rows2][cols2];

 

  for(i=0;i<rows2;i++)

      for(j=0;j<cols2;j++)

      {

          cout << "\nEnter element (" << i << "," << j << "): ";

          cin >> m2[i][j];

          cout << "\n";

      }

  cout << "\n";

  //Displaying Matrix 2

  for(i=0;i<rows2;i++)

  {

      for(j=0;j<cols2;j++)

          cout << m2[i][j] << " ";

      cout << "\n";

  }

     

  if(cols1!=rows2)

      cout << "operation is not supported";

  else

  {

      //Initializing results as 0

      for(i = 0; i < rows1; ++i)

  for(j = 0; j < cols2; ++j)

  mul[i][j]=0;

// Multiplying matrix m1 and m2 and storing in array mul.

  for(i = 0; i < rows1; i++)

  for(j = 0; j < cols2; j++)

  for(k = 0; k < cols1; k++)

  mul[i][j] += m1[i][k] * m2[k][j];

// Displaying the result.

  cout << "\n";

  for(i = 0; i < rows1; ++i)

      for(j = 0; j < cols2; ++j)

      {

      cout << " " << mul[i][j];

      if(j == cols2-1)

      cout << endl;

      }

      }  

  main();

 }

You might be interested in
A cold-rolled sheet metal that is 40 mm wide and has a thickness of 5.00 mm is going to be bent into a V shape with a 60° angle.
Artist 52 [7]
a= the force of gravity b= the amount of bicker to maple syrup ratio
5 0
3 years ago
A large plate is at rest in water at 15?C. The plate is suddenly translated parallel to itself, at 1.5 m/s. The resulting fluid
ratelena [41]

Answer:

Answer: (a) = 3.8187m/s, (b) =24.0858m/s (c) = = 3220.071m/s

   

Explanation:

du/u² = dt = ∫du/2.3183 = ∫dt

0.4313 u = t + c

(a) t = 0, u= 15m/s, c = 0.647

u = t+c/0.4313 = t + 0.647/0.4313

(a) when t= 1   u = 1+ 0.647/0.4313 = 3.8187m/s

(b) when t= 10   u = 10 + 0.647/0.4313 = 24.0858m/s

(c)when t= 1000  u = 1000 + 0.647/0.4313 = 3220.071m/s

5 0
3 years ago
I study to get good grades because my parents want to send me to the college of my choice.” This is an a. Intrinsic motivational
sashaice [31]

c. Both of These

hope it helps

lub.....

5 0
3 years ago
Read 2 more answers
You are an engineer in an electric-generation station. You know that the flames in the boiler reach a temperature of 1200 K and
olga nikolaevna [1]

Answer:

<em>The maximum efficiency the plant will ever achieve is 75%</em>

<em>Explanation:</em>

From the question given, we recall the following:

<em>Th flames in the boiler reaches a temperature of = 1200K</em>

<em>the cooling water is = 300K</em>

<em>The maximum efficiency the plant will achieve is defined as:</em>

Let nmax = 1 - Tmin /Tmax

Where,

Tmin = Minimum Temperature in plants

Tmax = Maximum Temperature in plants

The temperature of the cooling water  = Tmin = 300K

The temperature of the flames in boiler = Tmax = 1200k=K

The maximum efficiency becomes:

nmax =  1 - Tmin /Tmax

nmax =  1 - 300 /1200

nmax =  1-1/4 =0.75

nmax =  75%

5 0
4 years ago
This operating mode assists steering return after completing a turn.
castortr0y [4]

Answer:

In return mode, the system assists steering return after completing a turn. Information from the steering position sensor prevents the system from overshooting the center position. In dampener mode, the system acts like a hydraulic dampener to prevent kick back and bump steer.

3 0
2 years ago
Other questions:
  • Which of the following statements is true? Entropy has the unit of (A) Heat (B) Work (C) Energy (D) Heat capacity (E) Temperatur
    13·1 answer
  • A car engine operates with a thermal efficiency of 20%. Assume the air-conditioner has a coefficient of performance of β = 2 wor
    5·1 answer
  • 1. Implement the k-means clustering algorithm either in Java or Python. • The program should be executable with at least 3 param
    12·1 answer
  • An ideal fluid flows through a pipe made of two sections with diameters of 1.0 and 3.0 inches, respectively. The speed of the fl
    13·1 answer
  • 20 points and brainliest A, B, C, D
    11·2 answers
  • Need help tryna get a good grade
    9·2 answers
  • Which one of the following skills is a software engineer specializing in system support expected to possess?
    14·2 answers
  • 2.5
    15·1 answer
  • Tech A says that it is best to use a knife or other type of sharp tool to cut away the insulation when
    7·1 answer
  • As resistors are added in series to a circuit, the total resistance will
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!