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
What entrepreneurial activities do you know?are you capable of doing entrepreneurial activities
kherson [118]

Answer:

.,m

Explanation:

.,m

5 0
3 years ago
A gasoline engine has a piston/cylinder with 0.1 kg air at 4 MPa, 1527◦C after combustion, and this is expanded in a polytropic
Roman55 [17]

Answer:

The expansion work is 71.24 kJ and heat transfer is -16.89 kJ

Explanation:

From ideal gas law,

Initial volume (V1) = nRT/P

n is the number of moles of air in the cylinder = mass/MW = 0.1/29 = 0.00345 kgmol

R is gas constant = 8314.34 J/kgmol.K

T is initial temperature = 1527 °C = 1527+273 = 1800 K

P is initial pressure = 4 MPa = 4×10^6 Pa

V1 = 0.00345×8314.34×1800/(4×10^6) = 0.013 m^3

V2 = 10×V1 = 10×0.013 = 0.13 m^3

The process is a polytropic expansion process

polytropic exponent (n) = 1.5

P2 = P1(V1/V2)^n = 4×10^6(0.013/0.13)^1.5 = 1.26×10^5 Pa

Expansion work = (P1V1 - P2V2) ÷ (n - 1) = (4×10^6 × 0.013 - 1.26×10^5 × 0.13) ÷ (1.5 - 1) = 35620 ÷ 0.5 = 71240 J = 71240/1000 = 71.24 kJ

Heat transfer = change in internal energy + expansion work

change in internal energy (∆U) = Cv(T2 - T1)

T2 = PV/nR = 1.26×10^5 × 0.13/0.00345×8314.34 = 571 K

Cv = 20.785 kJ/kgmol.K

∆U = 20.785(571 - 1800) = -25544.765 kJ/kgmol × 0.00345 kgmol = -88.13 kJ

Heat transfer = -88.13 + 71.24 = -16.89 kJ

5 0
3 years ago
If you were to plot the voltage versus the current for a given circuit, what would you expect the slope of the line to be? If no
Brut [27]

Answer:

Part 1: It would be a straight line, current will be directly proportional to the voltage.

Part 2: The current would taper off and will have negligible increase after the voltage  reaches a certain  value. Graph attached.

Explanation:

For the first part, voltage and current have a linear relationship as dictated by the Ohm's law.

V=I*R

where V is the voltage, I is the current, and R is the resistance. As the Voltage increase, current is bound to increase too, given that the resistance remains constant.

In the second part, resistance is not constant. As an element heats up, it consumes more current because the free sea of electrons inside are moving more rapidly, disrupting the flow of charge. So, as the voltage increase, the current does increase, but so does the resistance. Leaving less room for the current to increase. This rise in temperature is shown in the graph attached, as current tapers.

7 0
3 years ago
On a average work day more than work place firs are reorted​
Basile [38]
What is the question? It looks like a statement...
8 0
3 years ago
The question belongs to Electrical Engineering (Linear System).
-Dominant- [34]
I’m crying looking at that.
5 0
3 years ago
Other questions:
  • Does the army good 4 you
    15·1 answer
  • Draw the sequence of BSTs that results when you insert the keys E, A, S, Y, Q, U, E, S, T, I, O, N, in that order into an initia
    10·1 answer
  • A specimen of some metal having a rectangular cross section 10.4 mm × 12.8 mm is pulled in tension with a force of 15900 N, whic
    6·1 answer
  • A civil engineer is analyzing the compressive strength of concrete. The compressive strength is approximately normal distributed
    7·1 answer
  • Researchers at the University of__________modified the iPhone to allow it to create medical images.
    9·2 answers
  • Fixed rate mortgage offer:
    9·2 answers
  • What Number Am I?
    13·1 answer
  • Report of invertor to convert 12 volt to 220 volt.
    6·1 answer
  • I need to solve for d
    11·2 answers
  • Read the passage.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!