special_forces

квадратная матрица

May 23rd, 2021
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.37 KB | None | 0 0
  1. #include "matrix.h"
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #include <math.h>
  4. #include <cstdio>
  5. #include <locale.h>
  6. #include <iostream>
  7. #include < cstdlib >
  8. //Классы должны соответствующим образом перегружать те операторы из набора (не менее семи): -, +,*,/,<,>,!=,==, которые имеют смысл для типа данных вашего вариант
  9. class matrix
  10. {
  11.     private:
  12.         int size;
  13. //        int str;
  14.         int* arr;
  15.     public:
  16.         matrix()//конструктор ничего не ввдоим
  17.         {
  18.            size = 2;
  19.            int** arr = new int* [2];
  20.            for (int i = 0; i < 2; i++) {
  21.                arr[i] = new int[2];
  22.            }
  23.            for (int i = 0; i < 2; i++)
  24.            {
  25.                for (int j = 0; j < 2; j++)
  26.                {
  27.                    arr[i] = 0;
  28.                }
  29.  
  30.            }
  31.            printf("Вызван конструктр1");
  32.         }
  33.         matrix(int n) //конструктор ничего не ввдоим
  34.         {
  35.             if (n < 2) {
  36.                 printf("Неправильно введен размер для матрицы ");
  37.                 exit(-2);
  38.             }
  39.            
  40.             size = n;
  41.             int** arr = new int* [size];
  42.             for (int i = 0; i < size; i++) {
  43.                 arr[i] = new int[size];
  44.             }
  45.             printf("Вызван конструктр2");
  46.  
  47.         } matrix operator *(const  matrix& other) //переделать.
  48.     {  
  49.         matrix temp;
  50.         if (this->size != other.size) {
  51.             printf("Разный размер матриц");
  52.             return temp;
  53.         }
  54.         matrix temp1(this->size);
  55.         for (int i = 0; i < size; i++)
  56.         {
  57.             for (int j = 0; j < size; j++)
  58.             {
  59.                 temp1.arr[i] = this->arr[i] * other.arr[i]; //изменить умножение
  60.  
  61.             }
  62.         }
  63.         return temp1;
  64.         size_t i, j;
  65.  
  66.         for (i = 0; i < size; ++i)
  67.             for (j = 0; j < size; ++j)
  68.             {
  69.                 size_t k;
  70.  
  71.                 result[i][j] = 0;//проблемое место
  72.  
  73.                 for (k = 0; k < size; ++k)
  74.                     result[i][j] += this->arr[i][k] * other.arr[k][j];
  75.             }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment