Guest User

Untitled

a guest
Oct 23rd, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.41 KB | None | 0 0
  1. #include <stdafx.h>
  2. #include <iostream>
  3. using namespace std;
  4.  
  5. class matrix
  6. {
  7.     int **a;
  8. public:
  9.     int str,stb;
  10.     matrix();
  11.     ~matrix();
  12.     void razmer();
  13.     void sozdanie();
  14.     void umnogenie(matrix m1,matrix m2);
  15.     void vivod();
  16. };
  17.  
  18. matrix::matrix()
  19. {
  20.     cout<<"Vvedite kolichestvo strok i stolbsov v pervoi matrice: ";
  21.     cin>>str>>stb;
  22.     a=new int*[str];
  23.     for(int i=0;i<stb;i++)
  24.         a[i]=new int;
  25. }
  26. matrix::~matrix()
  27. {
  28.     free(a);
  29. }
  30. void matrix::sozdanie()
  31. {
  32.     int scan;
  33.     cout<<"\n";
  34.     cout<<"Menu sozdania matrici:\n  1-ruchnoi vvod\n  2-avtozapolnenie\nscan: ";
  35.     cin>>scan;
  36.     for(int i=0;i<str;i++)
  37.         for(int j=0;j<stb;j++)
  38.             if(scan==1)
  39.             {
  40.                 cout<<"Vvedite["<<i+1<<"]"<<"["<<j+1<<"]"<<"element:";
  41.                 cin>>a[i][j];
  42.             }
  43.             else a[i][j]=rand()%9;
  44. }
  45.  
  46. void matrix::vivod()
  47. {
  48.     int i=0,j=0;
  49.     for(i=0;i<str;i++)
  50.     {
  51.         cout<<"\n";
  52.         for(j=0;j<stb;j++)
  53.         {
  54.             cout<<" ";
  55.             cout<<a[i][j];
  56.         }
  57.     }
  58. }
  59.  
  60. void matrix::umnogenie(matrix m1,matrix m2)
  61. {
  62.     for(int i=0;i<m1.stb;i++)
  63.         for(int j=0;j<m1.stb;j++)
  64.         {
  65.             a[i][j]=0;
  66.             for(int k=0;k<m1.stb;k++)
  67.                 a[i][j]+=m1.a[i][k]*m2.a[k][j];
  68.         }
  69. }
  70. int main()
  71. {
  72.     matrix m1,m2,m3;
  73.     m1.sozdanie();
  74.     cout<<"\nPervia matrica: ";
  75.     m1.vivod();
  76.     m2.sozdanie();
  77.     cout<<"\nVtoriaia matrica: ";
  78.     m2.vivod();
  79.     m3.str=m1.str;
  80.     m3.stb=m2.stb;
  81.     m3.umnogenie(m1,m2);
  82.     cout<<"\nRezultat umnigenia matrica: ";
  83.     m3.vivod();
  84.     scanf("%d");
  85.     return 0;
  86. }
Add Comment
Please, Sign In to add comment