Guest User

Untitled

a guest
Jan 12th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.96 KB | None | 0 0
  1.  
  2. #include "stdafx.h"
  3. #include <iostream>
  4. #include "matrix.h"
  5.  
  6. using namespace std;
  7.  
  8. void main ()
  9. {
  10. matrix a;
  11. int i=0;
  12. cout << "zapolnenie matrix_1 ------------------------\n";
  13. a.create1();
  14. cout << "zapolnenie matrix_2 ------------------------\n";
  15. a.create2();
  16.  
  17.  
  18. while (true)
  19. {
  20. cout << "Chto vi hotite sdelat` ? \n 1)Izmenit` element v matrix_1 ? \n 2)Izmenit` element v matrix_2 ? \n 3)Umnozhit` ? \n 4) slozit` ? \n 5) Print ?";
  21. cin >> i;
  22. switch (i)
  23. {
  24. case 1:
  25. a.izmenit();
  26. break;
  27. case 2:
  28. a.izmenit2();
  29. break;
  30. case 3:
  31. a.umnozhit();
  32. break;
  33. case 4:
  34. a.summa();
  35. break;
  36. case 5:
  37. a.print_mas();
  38. break;
  39. }
  40. }
  41. }
  42. _______________________________________________________________________--
  43.  
  44.  
  45. #include "StdAfx.h"
  46. #include "matrix.h"
  47. #include <iostream>
  48.  
  49. using namespace std;
  50.  
  51. matrix::matrix(void)
  52. {
  53. }
  54.  
  55. void matrix::create1()
  56. {
  57. int x=0,y=0,i=0;
  58. for (;x<=2;x++)
  59. {
  60. for (y=0;y<=2;y++)
  61. {
  62. cout << "Vvedite element mas[" << x <<"][" << y << "] = ?";
  63.  
  64. cin >> i;
  65.  
  66. m_matrix[x][y]=i;
  67. }
  68. }
  69. cout << "create Ok! \n";
  70.  
  71. }
  72. void matrix::izmenit()
  73. {
  74. int x=0,y=0,i=0;
  75. cout << "Vvedite x y elementa kotoriy hotite izmenit` \n";
  76. cin >> x;
  77. cin >> y;
  78. if(x > 1 && y > 1)
  79. {
  80. cout << "Oshibka vvoda!\n";
  81. return;
  82. }
  83. cout << "Vvedite znachenie ";
  84. cin >> i;
  85. m_matrix[x][y]=i;
  86. cout << "matrix[" << x << "][" << y << "]=" << m_matrix[x][y] << "\n";
  87. return;
  88. }
  89.  
  90. matrix::~matrix(void)
  91. {
  92. }
  93.  
  94. void matrix::print_mas()
  95. {
  96. int x=0,y=0;
  97. cout << "matrix_1 \n";
  98. for (;x<=2;x++)
  99. {
  100. for (y=0;y<=2;y++)
  101. {
  102. cout << m_matrix[x][y] << " ";
  103. }
  104. cout << "\n";
  105. }
  106.  
  107. cout << "matrix_2 \n";
  108. for (x=0;x<=2;x++)
  109. {
  110. for (y=0;y<=2;y++)
  111. {
  112. cout << m_matrix2[x][y] << " ";
  113. }
  114. cout << "\n";
  115. }
  116. }
  117.  
  118. void matrix::summa()
  119. {
  120. int x=0,y=0,i=0;
  121. cout << "Summa------------------------\n";
  122. for (;x<=2;x++)
  123. {
  124. for (y=0;y<=2;y++)
  125. {
  126. cout << m_matrix[x][y] + m_matrix2[x][y] << " " ;
  127. }
  128. cout << "\n";
  129. }
  130. }
  131.  
  132. void matrix::create2()
  133. {
  134. int x=0,y=0,i=0;
  135. for (;x<=2;x++)
  136. {
  137. for (y=0;y<=2;y++)
  138. {
  139. cout << "Vvedite element mas[" << x <<"][" << y << "] = ?";
  140.  
  141. cin >> i;
  142.  
  143. m_matrix2[x][y]=i;
  144. }
  145. }
  146. cout << "create Ok! \n";
  147.  
  148. }
  149.  
  150. void matrix::izmenit2()
  151. {
  152. int x=0,y=0,i=0;
  153. cout << "Vvedite x y elementa kotoriy hotite izmenit` \n";
  154. cin >> x;
  155. cin >> y;
  156. if(x > 1 && y > 1)
  157. {
  158. cout << "Oshibka vvoda!\n";
  159. return;
  160. }
  161. cout << "Vvedite znachenie ";
  162. cin >> i;
  163. m_matrix2[x][y]=i;
  164. cout << "matrix[" << x << "][" << y << "]=" << m_matrix2[x][y] << "\n";
  165. return;
  166. }
  167. void matrix::umnozhit()
  168. {
  169. int x=0,y=0,i=0,x1=0,y1=0,q1=0,q2=0,q3=0;
  170. cout << "Umnozhit------------------------\n";
  171. for(;x1<=2;x1++)
  172. {
  173. for (x=0;x<=2;x++)
  174. {
  175. for (y=0;y<=2;y++)
  176. {
  177. q1 += m_matrix[x1][y] * m_matrix2[y][x] ;
  178.  
  179. }
  180.  
  181. cout << q1 << " ";
  182. q1=0;
  183. }
  184. cout << "\n";
  185.  
  186. }
  187. }
Add Comment
Please, Sign In to add comment