Guest User

Untitled

a guest
Jun 21st, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class Matrix{
  6. double p[3][3];
  7. double q[3][3];
  8. double r[3][3];
  9. public:
  10. void mult(double p[3][3], double q[3][3]);
  11. void output();
  12.  
  13. };
  14.  
  15. void Matrix::mult(double p[3][3], double q[3][3])
  16. {
  17.  
  18. int num = 0;
  19. int j = 0;
  20. for(int i = 0; i < 3; i++)
  21. {
  22. num = 0;
  23. for(j = 0; j < 3; j++)
  24. {
  25. if(num < 3)
  26. {
  27. r[num][i] += (p[j][i] * r[num][j]);
  28. if(j == 2)
  29. {
  30. num ++;
  31. j = 0;
  32. }
  33. }
  34. }
  35.  
  36. }
  37.  
  38. }
  39. void Matrix::output()
  40. {
  41. int i = 0;
  42. int j = 0;
  43. cout << "Results:\n";
  44. for(int i = 0; i < 3; i++)
  45. {
  46. for (int j = 0; j < 3; j++)
  47. {
  48. cout << r[i][j] << " ";
  49. }
  50. cout << "\n";
  51. }
  52. }
  53.  
  54.  
  55.  
  56. int main()
  57. {
  58. double x[3][3];
  59. double y[3][3];
  60.  
  61. Matrix answer;
  62. int i = 0;
  63. int j = 0;
  64.  
  65. cout << "Enter values of the first Matrix left to right.\n";
  66. for(int i = 0; i < 3; i++)
  67. {
  68. for (int j = 0; j < 3; j++)
  69. {
  70. cin >> x[i][j];
  71. }
  72. }
  73.  
  74. cout << "Enter values of the second Matrix left to right.\n";
  75. for(int i = 0; i < 3; i++)
  76. {
  77. for (int j = 0; j < 3; j++)
  78. {
  79. cin >> y[i][j];
  80. }
  81. }
  82. answer.mult(x, y);
  83. answer.output();
  84. int hold; //holds the Console open.
  85. cin >> hold;
  86. cin.ignore();
  87.  
  88. }
Add Comment
Please, Sign In to add comment