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
In order to avoid a rollover, what is the highest degree incline one should mow on? 10-degree incline 5-degree incline 30-degree
ser-zykov [4K]

Answer: B: 20-degree incline

Explanation:

A tractor user should avoid slopes of more than 20 degrees in order to avoid rollovers

6 0
2 years ago
A 15.00 mL sample of a solution of H2SO4 of unknown concentration was titrated with 0.3200M NaOH. the titration required 21.30 m
natima [27]

Answer:

a. 0.4544 N

b. 5.112 \times 10^{-5 M}

Explanation:

For computing the normality and molarity of the acid solution first we need to do the following calculations

The balanced reaction

H_2SO_4 + 2NaOH = Na_2SO_4 + 2H_2O

NaOH\ Mass = Normality \times equivalent\ weight \times\ volume

= 0.3200 \times 40 g \times 21.30 mL \times  1L/1000mL

= 0.27264 g

NaOH\ mass = \frac{mass}{molecular\ weight}

= \frac{0.27264\ g}{40g/mol}

= 0.006816 mol

Now

Moles of H_2SO_4 needed  is

= \frac{0.006816}{2}

= 0.003408 mol

Mass\ of\ H_2SO_4 = moles \times molecular\ weight

= 0.003408\ mol \times 98g/mol

= 0.333984 g

Now based on the above calculation

a. Normality of acid is

= \frac{acid\ mass}{equivalent\ weight \times volume}

= \frac{0.333984 g}{49 \times 0.015}

= 0.4544 N

b. And, the acid solution molarity is

= \frac{moles}{Volume}

= \frac{0.003408 mol}{15\ mL \times  1L/1000\ mL}

= 0.00005112

=5.112 \times 10^{-5 M}

We simply applied the above formulas

4 0
3 years ago
2. Why are some constraints automatically applied by the software, but you must manually apply others?
hoa [83]

Answer:

It is because constraints applied automatic by the software (CAD) are supposed to control relationships and geometry between lines, arcs and circles while those manually added are supposed to control the geometry to behave in the manner the user likes the sketch to appear when drawing.

Explanation:

CAD software enables creating sketches using the program by automatic allowing geometric constraints to perform the tasks.Geometry in lines, circles, and other geometric features show collaborating relation that facilitate sketching in the program.For example, two end points appear to make lines remain perpendicular.Other geometric constraints are parallel, and equal.However, the user can manually apply geometric constraints to a sketch to force the geometry in a manner that is suitable to the sketch drawn.That is why a user must manually apply others.

7 0
3 years ago
A 200‑m rigid vessel contains a saturated liquid‑vapor mixture with a vapor quality of 75%. The temperature of the vessel is mai
DerKrebs [107]

Answer:

Given,

Temperature;

T = 393;;K

Convert to Celcius;

T = (393-273) degrees

T = 120°C

Using Table A-4 (Saturated water - Temperature table), at T = 120 C;

vf = 0.001060 m³/kg

vg = 0.89133 m³/kg

Quality is given as;

75% = 0.75

Specific volume is given as;

v = vf + x (vg - vf) = 0.001060 + 0.75(0.89133 _ 0.001060)

v= 0.66876 m³/kg

We know;

v = V/m

0.66876  = 100/m

m = 149.53 kg

6 0
3 years ago
The part of a circuit that carries the flow of electrons is referred to as the?
Oksanka [162]

Answer:

  Conductor

Explanation:

Current is carried by a conductor.

__

The purpose of a dielectric and/or insulator is to prevent current flow. An electrostatic field may set up the conditions for current flow, but it carries no current itself.

7 0
3 years ago
Other questions:
  • What is the major drawback in nanocrystalline alloys? a)- high brittleness b)-low hardness c)-rapid grain growth upon heating d)
    9·1 answer
  • A 3.5-m3 rigid tank initially contains air whose density is 2 kg/m3 . The tank is connected to a high-pressure supply line throu
    8·1 answer
  • Using any of the bilinear transform, matched pole-zero, or impulse invariance techniques in converting a continuous-time system
    14·2 answers
  • ____ technologies are new technologies that are not currently widely employed.
    15·2 answers
  • -0-1"<br> -0<br> -20<br> -15<br> -10<br> 0<br> -5
    9·1 answer
  • For the Mohr's circle of a plane-strain element, which of the following changes as a result of shear strain change?
    7·1 answer
  • Which of these are an ethical issue
    14·1 answer
  • Binary classification algorithm
    9·1 answer
  • Given the inherent costs of regulation it is safe to say that there is always a negative economic impact associated with regulat
    7·1 answer
  • Air at 403 K and 1 atm enters a convergent nozzle at a velocity of 150
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!