Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.45 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <vector>
  4. #include <ctime>
  5. #include <iomanip>
  6.  
  7. using namespace std;
  8. class Vector;
  9. class Matrix
  10. {
  11. public:
  12. int matrix[100][100], // статический массив
  13. rows = 0, // строки
  14. columns = 0; // столбцы
  15. friend void mulData(Matrix& m, Vector& v);
  16. Matrix()
  17. {
  18. rows = 5;
  19. columns = 5;
  20. srand(time(0));
  21. for (int ix = 0; ix < rows; ix++)
  22. for (int jx = 0; jx < columns; jx++)
  23. matrix[ix][jx] = rand() % 10 + 1;
  24. }
  25. Matrix(int r, int c)
  26. {
  27. rows = r;
  28. columns = c;
  29. srand(time(0));
  30. for (int ix = 0; ix < rows; ix++)
  31. for (int jx = 0; jx < columns; jx++)
  32. matrix[ix][jx] = rand() % 10 + 1;
  33. }
  34. Matrix(const Matrix& m)
  35. {
  36. rows = m.rows;
  37. columns = m.columns;
  38. for (int ix = 0; ix < rows; ix++)
  39. for (int jx = 0; jx < columns; jx++)
  40. matrix[ix][jx] = m.matrix[ix][jx];
  41. }
  42. void cout_m()
  43. {
  44. for (int ix = 0; ix < rows; ix++)
  45. {
  46. for (int jx = 0; jx < columns; jx++)
  47. {
  48. cout << setw(4) << matrix[ix][jx];
  49. }
  50. cout << endl;
  51. }
  52. cout << endl;
  53. }
  54. ~Matrix()
  55. {
  56. }
  57. };
  58.  
  59. class Vector
  60. {
  61. public:
  62. int vector[100];
  63. int vector_size = 0;
  64. friend void mulData(Matrix& m, Vector& v);
  65. Vector()
  66. {
  67. vector_size = 5;
  68. for (int jx = 0; jx < vector_size; jx++)
  69. vector[jx] = rand() % 10 + 1;
  70. }
  71. Vector(int v_sz)
  72. {
  73. vector_size = v_sz;
  74. for (int jx = 0; jx < vector_size; jx++)
  75. vector[jx] = rand() % 10 + 1;
  76. }
  77. Vector(const Vector& vec)
  78. {
  79. vector_size = vec.vector_size;
  80. for (int jx = 0; jx < vector_size; jx++)
  81. vector[jx] = vec.vector[jx];
  82. }
  83. void cout_v()
  84. {
  85. for (int ix = 0; ix < vector_size; ix++)
  86. {
  87. cout << setw(4) << vector[ix] << endl;
  88. }
  89. cout << endl;
  90. }
  91. ~Vector()
  92. {
  93. }
  94. };
  95.  
  96. void mulData(Matrix& m, Vector& v)
  97. {
  98. int out[100]; // выходной вектор
  99. // умножение элементов матрицы на вектор
  100. for (int ix = 0; ix < m.rows; ix++)
  101. {
  102. out[ix] = 0;
  103. for (int jx = 0; jx < m.columns; jx++)
  104. out[ix] += m.matrix[ix][jx] * v.vector[jx];
  105. }
  106. m.cout_m();
  107. v.cout_v();
  108. for (int ix = 0; ix < m.rows; ix++)
  109. {
  110. cout << out[ix] << " ";
  111. }
  112. cout << endl;
  113. }
  114.  
  115. int main()
  116. {
  117.  
  118. Matrix m;
  119. Vector v;
  120. mulData(m, v);
  121.  
  122. system("PAUSE");
  123. return 0;
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement