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
Swing arm restraints are intended to prevent a vehicle from falling off a lift.
castortr0y [4]

The question is asking whether that statement is true or false. Options are;

A) True

B) False

This is about usage of Swing arm restraints.

<em><u>B) False</u></em>

There are different safety features that people employ when a vehicle is lifted. However, for this question, we will only talk about swing arm restraints.

  • Swing arm restraints are lifting restraint devices that are used to prevent a cars arms from shifting or going out of position after that car has been lifted and mounted.

  • This swing arm restraint does not prevent a vehicle from falling off a lift as it just helps to ensure that the swing arms that are unloaded basically maintain their position.

Read more at; brainly.com/question/17972874

4 0
3 years ago
Your family has asked you to estimate the operating costs of your clothes dryer for the year. The clothes dryer in your home has
trasher [3.6K]

Answer:

The costs to run the dryer for one year are $ 9.03.

Explanation:

Given that the clothes dryer in my home has a power rating of 2250 Watts, and to dry one typical load of clothes the dryer will run for approximately 45 minutes, and in Ontario, the cost of electricity is $ 0.11 / kWh, to calculate the costs to run the dryer for one year the following calculation must be performed:

1 watt = 0.001 kilowatt

2250/45 = 50 watts per minute

45 x 365 = 16,425 / 60 = 273.75 hours of consumption

50 x 60 = 300 watt = 0.3 kw / h

0.3 x 273.75 = 82.125

82.125 x 0.11 = 9.03

Therefore, the costs to run the dryer for one year are $ 9.03.

8 0
3 years ago
failure to yield the right-of-way to another vehicle or pedestrian is the primary Collision factor in about 20% of fatal and inj
laila [671]

You could just create a turn on green arrow. Have a button for pedestrians. The only way for them to turn is if they have a green arrow and the green arrow will only appear when pedestrians are stopped or finished walking and all cars are clear or fully stopped

8 0
4 years ago
Alfamebimizde kaç harf var?<br>​
fredd [130]

Answer:

hi

Explanation:

The modern English alphabet is a Latin alphabet consisting of 26 letters, each having an upper- and lower-case form. It originated around the 7th century from Latin script. Since then, letters have been added or removed to give the current Modern English alphabet of 26 letters with no diacritics, diagraphs, and special characters. The word alphabet is a compound of the first two letters of the Greek alphabet, alpha and beta.

Have a nice day

8 0
3 years ago
Compute the number of games using the formula of “SINGLE ROUND ROBIN” and plot the games in a table:
Bogdan [553]

Answer:

N=27.02

Explanation:

3 0
2 years ago
Other questions:
  • What are factor of safety for brittle and ductile material
    5·1 answer
  • Megan is an architect who is creating a building design. Which is a prominent technical aspect that she needs to keep in mind wh
    12·1 answer
  • What fuel do rockets use
    9·2 answers
  • A 200‑m rigid vessel contains a saturated liquid‑vapor mixture with a vapor quality of 75%. The temperature of the vessel is mai
    5·1 answer
  • Do all websites use the same coding to create?
    8·1 answer
  • What does the supply chain management process involve
    6·1 answer
  • Which Finance jobs can someone pursue with only a high school diploma? Check all that apply.
    10·2 answers
  • Refrigerant-134a enters the expansion valve of a refrigeration system at 120 psia as a saturated liquid and leaves at 20 psia. D
    15·1 answer
  • The side area of the door shell that is concealed when the door is closed is called the:
    15·1 answer
  • Briefly explain the term soil sampling and outline its importance in building engineering works.
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!