Advertisement
Guest User

Untitled

a guest
Dec 10th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. class Matrics1{
  4. public:
  5. int n;
  6. int **arr;
  7. Matrics1(int k);
  8. };
  9.  
  10. class Matrics2{
  11. public:
  12. int n;
  13. int **arr;
  14. Matrics2(int k);
  15. };
  16. Matrics1::Matrics1(int k){
  17. n = k;
  18. for(int i = 0; i < k; i++){
  19. for(int j = 0; j < k; j++){
  20. arr[i][j] = 1;
  21. }
  22. }
  23. };
  24. Matrics2::Matrics2(int k){
  25. n = k;
  26. for(int i = 0; i < k; i++){
  27. for(int j = 0; j < k; j++){
  28. arr[i][j] = 1;
  29. }
  30. }
  31. };
  32. template<typename T>
  33. void memAlloc(T &m) {
  34. m.arr = new int *[m.n];
  35. for (int i = 0; i < m.n; i++) {
  36. m.arr[i] = new int[m.n];
  37. }
  38. }
  39. template<typename T>
  40. void memDel(T &m) {
  41. for (int i = 0; i < m.n; i++) {
  42. delete[] m.arr[i];
  43. }
  44. delete[] m.arr;
  45. }
  46.  
  47.  
  48. int main() {
  49. Matrics1 m(5);
  50. memAlloc(m);
  51. Matrics2 b(5);
  52. memAlloc(b);
  53. memDel(m);
  54. memDel(b);
  55. //суммирование матриц
  56. for(int i = 0; i < m.n; i++){
  57. for(int j = 0; j < m.n; j++){
  58. m.arr[i][j] += b.arr[i][j];
  59. cout << m.arr[i][j] << ' ';
  60. }
  61. cout << endl;
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement