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
Why dose bob not let humans touch him one and only Ivan
gogolik [260]
Sorry man i don’t know sorry
8 0
2 years ago
Is an example of an electrical device.
Yuki888 [10]
I think that it is all of the above
5 0
3 years ago
Read 2 more answers
What is the objective of phasing out an INDUCTION MOTOR before putting the machine into commission?
enyata [817]

The main objective of phasing out an INDUCTION MOTOR is to identify the ends of the stator coils.

<h3>What is an induction motor?</h3>

An induction motor is a device based on alternate electricity (AC) which is composed of three different stator coils.

An induction motor is a device also known as an asynchronous motor due to its irregular velocity.

In conclusion, the objective of phasing out an INDUCTION MOTOR is to identify the ends of the stator coils.

Learn more on induction motors here:

brainly.com/question/15721280

#SPJ1

8 0
2 years ago
What is Pressure measured from absolute zero pressure called?
7nadin3 [17]
Anything greater than total vacuum is technically a form of pressure
5 0
3 years ago
Ronny wants to calculate the mechanical advantage. He needs to determine the length of the effort arm and the length of the load
kakasveta [241]

Answer:

I hope it's helpful.

Explanation:

Simple Machines

Experiments focus on addressing areas pertaining to the relationships between effort force, load force, work, and mechanical advantage, such as: how simple machines change the force needed to lift a load; mechanical advantages relation to effort and load forces; how the relationship between the fulcrum, effort and load affect the force needed to lift a load; how mechanical advantage relates to effort and load forces and the length of effort and load arms.

Through investigations and models created with pulleys and levers, students find that work in physical terms is a force applied over a distance. Students also discover that while a simple machine may make work seem easier, in reality the amount of work does not decrease. Instead, machines make work seem easier by changing the direction of a force or by providing mechanical advantage as a ratio of load force to effort force.

Students examine how pulleys can be used alone or in combination affect the amount of force needed to lift a load in a bucket. Students find that a single pulley does not improve mechanical advantage, yet makes the effort applied to the load seem less because the pulley allows the effort to be applied in the direction of the force of gravity rather than against it. Students also discover that using two pulleys provides a mechanical advantage of 2, but that the effort must be applied over twice the distance in order to gain this mechanical advantage Thus the amount of work done on the load force remains the same.

Students conduct a series of experiments comparing the effects of changing load and effort force distances for the three classes of levers. Students discover that when the fulcrum is between the load and the effort (first class lever), moving the fulcrum closer to the load increases the length of the effort arm and decreases the length of the load arm. This change in fulcrum position results in an increase in mechanical advantage by decreasing the amount of effort force needed to lift the load. Thus, students will discover that mechanical advantage in levers can be determined either as the ratio of load force to effort force, or as the ratio of effort arm length to load arm length. Students then predict and test the effect of moving the fulcrum closer to the effort force. Students find that as the length of the effort arm decreases the amount of effort force required to lift the load increases.

Students explore how the position of the fulcrum and the length of the effort and load arms in a second-class lever affect mechanical advantage. A second-class lever is one in which the load is located between the fulcrum and the effort. In a second-class lever, moving the load changes the length of the load arm but has no effect on the length of the effort arm. As the effort arm is always longer than the load arm in this type of lever, mechanical advantage decreases as the length of the load arm approaches the length of the effort arm, yet will always be greater than 1 because the load must be located between the fulcrum and the effort.

Students then discover that the reverse is true when they create a third-class lever by placing the effort between the load and the fulcrum. Students discover that in the case of a third-class lever the effort arm is always shorter than the load arm, and thus the mechanical advantage will always be less than 1. Students also create a model of a third-class lever that is part of their daily life by modeling a human arm.

The CELL culminates with a performance assessment that asks students to apply their knowledge of simple machine design and mechanical advantage to create two machines, each with a mechanical advantage greater than 1.3. In doing so, students will demonstrate their understanding of the relationships between effort force, load force, pulleys, levers, mechanical advantage and work. The performance assessment will also provide students with an opportunity to hone their problem-solving skills as they test their knowledge.

Through this series of investigations students will come to understand that simple machines make work seem easier by changing the direction of an applied force as well as altering the mechanical advantage by afforded by using the machine.

Investigation focus:

Discover that simple machines make work seem easier by changing the force needed to lift a load.

Learn how effort and load forces affect the mechanical advantage of pulleys and levers.

8 0
2 years ago
Other questions:
  • 7 Single-use earplugs require a professional fitting before they can be used.
    10·2 answers
  • Not a characteristic property of ceramic material (a) high temperature stability (b) high mechanical strength (c) low elongation
    7·2 answers
  • A 356 cast aluminum test bar is tested in tension. The initial gage length as marked on the sample is 50mm and the initial diame
    9·1 answer
  • 3. (9 points) A square-thread power screw is used to raise or lower the basketball board in a gym, the weight of which is W = 10
    12·1 answer
  • The average human heart Beats 1.15 times 10 to the power of 5 per day. There are 3.65 times 10 to the power of 2 days in one yea
    14·1 answer
  • A spring (70 N/m ) has an equilibrium length of 1.00 m. The spring is compressed to a length of 0.50 m and a mass of 2.2 kg is p
    14·2 answers
  • How do guest room hotel smoke alarms work and differ then regular home versions?
    10·2 answers
  • A lightbulb has a fixed negative and positive connector. You cannot swap positive and negative sides of a lightbulb in a circuit
    9·2 answers
  • The only way to know if a design will work in real-world conditions is to build a model, or prototype, based on the plan. This i
    7·2 answers
  • As you push a toggle bolt into a wall, the
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!