Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <climits>
- #include <ctime>
- #include <cstdlib>
- using namespace std;
- struct sMatrix
- {
- int matrix[20][20];
- int s;
- int o;
- sMatrix(int so,int osz)
- {
- s=so;
- o=osz;
- for(int i=0;i<s;i++)
- for(int k=0;k<o;k++)
- matrix[i][k]=0;
- }
- virtual void feltolt(int a,int b);
- };
- void sMatrix::feltolt(int s,int o)
- {
- for(int i=0;i<s;i++)
- {
- for(int k=0;k<o;k++)
- {
- int l=rand()%8+1;
- matrix[i][k]=l;
- }
- }
- }
- void kiir(sMatrix *k)
- {
- for(int i=0;i<k->o;i++)
- {cout<<endl;
- for(int j=0;j<k->s;j++)
- cout<<k->matrix[i][j]<<" ";
- }
- cout<<endl;
- cout<<endl;
- }
- void sum(sMatrix *a,sMatrix *b)
- {
- for(int i=0;i<a->o;i++)
- {cout<<endl;
- for(int k=0;k<a->s;k++)
- cout<<a->matrix[i][k]+b->matrix[i][k]<<" ";
- }
- cout<<endl<<endl;
- }
- void szorzat(sMatrix *a, sMatrix *b)
- {
- sMatrix *c;
- c=new sMatrix(3,3);
- c->feltolt(3,3);
- for(int i=0;i<a->s;i++)
- for(int j=0;j<b->o;j++)
- for(int k=0;k<b->s;k++)
- c->matrix[i][j]=c->matrix[i][j]+a->matrix[i][k]*b->matrix[k][j];
- for(int i=0;i<c->s;i++)
- {
- cout<<endl;
- for(int k=0;k<c->o;k++)
- cout<<c->matrix[i][k]<<" ";
- }
- cout<<endl;
- }
- void kivonas(sMatrix *a,sMatrix *b)
- {
- for(int i=0;i<a->o;i++)
- {cout<<endl;
- for(int k=0;k<a->s;k++)
- cout<<a->matrix[i][k]-b->matrix[i][k]<<" ";
- }
- cout<<endl<<endl;
- }
- void szorazataval(int x,sMatrix *a)
- {
- for(int i=0;i<a->o;i++)
- {cout<<endl;
- for(int k=0;k<a->s;k++)
- {
- a->matrix[i][k]*=x;
- cout<<a->matrix[i][k]<<" ";
- }
- }
- cout<<endl;
- }
- int main()
- {
- srand(time(NULL));
- sMatrix *a;
- a=new sMatrix(3,3);
- a->feltolt(3,3);
- sMatrix *b;
- b=new sMatrix(3,3);
- b->feltolt(3,3);
- cout<<"A:";
- kiir(a);
- cout<<"B:";
- kiir(b);
- cout<<"A + B =";
- sum(a,b);
- cout<<"A - B =";
- kivonas(a,b);
- cout<<"A * B =";
- szorzat(a,b);
- cout<<endl<<"A * x ="<<endl;
- int tx;cout<<"x= ";cin>>tx;
- szorazataval(tx,a);
- cout<<"B * x ="<<endl;
- cout<<"x= ";cin>>tx;
- szorazataval(tx,b);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement