Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Matrica
- {
- private:
- float matr[10][10];
- int red;
- int kol;
- public:
- Matrica()
- {
- red = 0;
- kol = 0;
- for(int i=0;i<10;i++ )
- for(int j=0;j<10;j++)
- matr[i][j] = 0;
- }
- Matrica operator+(Matrica const& mat)
- {
- Matrica tp;
- tp.red = mat.red;
- tp.kol = mat.kol;
- for(int i=0;i<mat.red;i++)
- for(int j=0;j<mat.kol;j++ )
- tp.matr[i][j] = mat.matr[i][j] + matr[i][j];
- return tp;
- }
- Matrica operator-( Matrica const& mat )
- {
- Matrica tp;
- tp.red = mat.red;
- tp.kol = mat.kol;
- for(int i=0;i<mat.red;i++)
- for(int j=0;j<mat.kol;j++)
- tp.matr[i][j] = matr[i][j] - mat.matr[i][j];
- return tp;
- }
- Matrica operator*( Matrica const& mat)
- {
- Matrica tp;
- tp.red = mat.red;
- tp.kol = mat.kol;
- for(int i=0;i<mat.red;i++)
- for(int j=0;j<mat.kol;j++)
- {
- float v=0;
- for(int x=0;x<mat.red;x++)
- v += matr[i][x] * mat.matr[x][j];
- tp.matr[i][j]=v;
- }
- return tp;
- }
- Matrica operator+( int const& broj )
- {
- Matrica tp;
- tp.red=red;
- tp.kol=kol;
- for(int i=0;i<red;i++)
- for(int j=0;j<kol;j++)
- tp.matr[i][j] = matr[i][j] + broj;
- return tp;
- }
- friend istream& operator>>( istream& in, Matrica& mat );
- friend ostream& operator<<( ostream& out, Matrica& mat );
- };
- istream& operator>>( istream& in, Matrica& mat )
- {
- in >> mat.red;
- in >> mat.kol;
- for(int i=0;i<mat.red;i++)
- for(int j=0;j<mat.kol;j++)
- in >> mat.matr[i][j];
- return in;
- }
- ostream& operator<<( ostream& out, Matrica& mat )
- {
- for(int i=0;i<mat.red;i++)
- {
- for( int j=0;j<mat.kol;j++)
- out<<mat.matr[i][j]<<" ";
- out<<endl;
- }
- return out;
- }
- int main()
- {
- Matrica A,B,C;
- cin>>A>>B>>C;
- Matrica D=B*C;
- Matrica R=A-D+2;
- cout<<R;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement