Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdafx.h>
- #include <iostream>
- using namespace std;
- class matrix
- {
- int **a;
- public:
- int str,stb;
- matrix();
- ~matrix();
- void razmer();
- void sozdanie();
- void umnogenie(matrix m1,matrix m2);
- void vivod();
- };
- matrix::matrix()
- {
- cout<<"Vvedite kolichestvo strok i stolbsov v pervoi matrice: ";
- cin>>str>>stb;
- a=new int*[str];
- for(int i=0;i<stb;i++)
- a[i]=new int;
- }
- matrix::~matrix()
- {
- free(a);
- }
- void matrix::sozdanie()
- {
- int scan;
- cout<<"\n";
- cout<<"Menu sozdania matrici:\n 1-ruchnoi vvod\n 2-avtozapolnenie\nscan: ";
- cin>>scan;
- for(int i=0;i<str;i++)
- for(int j=0;j<stb;j++)
- if(scan==1)
- {
- cout<<"Vvedite["<<i+1<<"]"<<"["<<j+1<<"]"<<"element:";
- cin>>a[i][j];
- }
- else a[i][j]=rand()%9;
- }
- void matrix::vivod()
- {
- int i=0,j=0;
- for(i=0;i<str;i++)
- {
- cout<<"\n";
- for(j=0;j<stb;j++)
- {
- cout<<" ";
- cout<<a[i][j];
- }
- }
- }
- void matrix::umnogenie(matrix m1,matrix m2)
- {
- for(int i=0;i<m1.stb;i++)
- for(int j=0;j<m1.stb;j++)
- {
- a[i][j]=0;
- for(int k=0;k<m1.stb;k++)
- a[i][j]+=m1.a[i][k]*m2.a[k][j];
- }
- }
- int main()
- {
- matrix m1,m2,m3;
- m1.sozdanie();
- cout<<"\nPervia matrica: ";
- m1.vivod();
- m2.sozdanie();
- cout<<"\nVtoriaia matrica: ";
- m2.vivod();
- m3.str=m1.str;
- m3.stb=m2.stb;
- m3.umnogenie(m1,m2);
- cout<<"\nRezultat umnigenia matrica: ";
- m3.vivod();
- scanf("%d");
- return 0;
- }
Add Comment
Please, Sign In to add comment