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
Please help me I don’t understand
Lapatulllka [165]

Answer:

A battery changes chemical energy to <u>electrical</u> energy

A drum changes mechanical energy to <u>sound</u> energy

Explanation:

A battery is a device that stores chemical energy and converts it to electrical energy.

Beating a drum represents a mechanical to sound energy  conversion.

4 0
3 years ago
Read 2 more answers
If you measure 0.7 V across a diode, the diode is probably made of
tatuchka [14]

Answer:

Made of Silicon.

Explanation:

A diode is a semiconductor device use in mostly electronic appliances. It is two terminals device consisting of a P-N junction formed either in Germanium or silicon crystal.

Diode can be forward biased or reverse biased.

When a diode is forward biased and the applied voltage is increased from zero, hardly any current flows through the device in the beginning.

It is so because the external voltage is being opposed by the internal barrier voltage whose value is 0.7v for silicon and 0.3v for germanium.

If you measure 0.7 V across a diode, the diode is probably therefore made of Silicon.

6 0
3 years ago
A geothermal heat pump absorbs 15 KJ/s of heat from the Earth 15 m below a house. This heat pump uses a 7.45 kJ/s compressor.
Anna007 [38]

Answer:

COP of the heat pump is 3.013

OP of the cycle is  1.124

Explanation:

W = Q₂ - Q₁

Given

a)

Q₂ = Q₁ + W

     = 15 + 7.45

     = 22.45 kw

COP = Q₂ / W = 22.45 / 7.45 = 3.013

b)

Q₂ = 15 x 1.055 = 15.825 kw

therefore,

Q₁ = Q₂ - W

Q₁ = 15.825 - 7.45 = 8.375

∴ COP = Q₁ / W = 8.375 / 7.45 = 1.124

4 0
4 years ago
Read 2 more answers
Calculate the torque produced by a motor that has 500 windings across a 30cm diameter rotating core. The core is 0.6 M long insi
zalisa [80]

Answer:

hhjhfdddvhyyjjvfrryjjbcdryuj vdryujbcr4yug

7 0
3 years ago
Un mol de gas ideal realiza un trabajo de 3000 J sobre su entorno, cuando se expande de manera isotermica a una temperatura de 5
Shkiper50 [21]

Answer:

74,4 litros

Explanation:

Dado que

W = nRT ln (Vf / Vi)

W = 3000J

R = 8,314 JK-1mol-1

T = 58 + 273 = 331 K

Vf = desconocido

Vi = 25 L

W / nRT = ln (Vf / Vi)

W / nRT = 2.303 log (Vf / Vi)

W / nRT * 1 / 2.303 = log (Vf / Vi)

Vf / Vi = Antilog (W / nRT * 1 / 2.303)

Vf = Antilog (W / nRT * 1 / 2.303) * Vi

Vf = Antilog (3000/1 * 8,314 * 331 * 1 / 2,303) * 25

Vf = 74,4 litros

3 0
3 years ago
Other questions:
  • To be able to write an ss-domain equation for a circuit, use partial fraction decomposition to separate the terms in this equati
    12·1 answer
  • What are the advantages of using 3D ink jet printing?
    10·1 answer
  • Two balanced Y-connected loads in parallel, one drawing 15kW at 0.6 power factor lagging and the other drawing 10kVA at 0.8 powe
    13·1 answer
  • Design a posttest-only experiment that would test each of the following causal claims. For each one, identify the study’s indepe
    13·1 answer
  • When the rod is circular, radial lines remain straight and sections perpendicular to the axis do not warp. In this case, the str
    11·1 answer
  • Waste that is generated by a business is called a _____________.
    14·2 answers
  • Brainliest need help
    15·1 answer
  • How does data mining help interactive marketing for a business?
    5·1 answer
  • The first thing you should do is develop a ____________________ to determine what vehicle you can afford.
    12·1 answer
  • Which of the following situations best describes student engaged in active learning
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!