Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include <cstring>
- using namespace std;
- class Matrix
- {
- protected:
- float matrix[10][10];
- int rows;
- int columns;
- /** void copy(const Matrix &m)
- {
- this->rows=m.rows;
- this->columns=m.columns;
- for(int i = 0 ; i < rows ; i ++)
- {
- for(int j = 0 ; j < columns ; j ++)
- {
- this->matrix[i][j]=m.matrix[i][j];
- }
- }
- }
- **/
- public:
- Matrix(){}
- Matrix(int rows , int columns)
- {
- this->rows=rows;
- this->columns=columns;
- for(int i = 0 ; i < rows ; i ++)
- {
- for(int j = 0 ; j < columns ; j ++)
- {
- this->matrix[i][j]=0;
- }
- }
- }
- // Matrix (const Matrix &s){copy(s);}
- Matrix &operator +(int s)
- {
- for(int i = 0 ; i < rows ; i ++)
- {
- for(int j = 0 ; j < columns ; j ++)
- {
- matrix[i][j]+=s;
- }
- }
- return *this;
- }
- Matrix &operator-(Matrix &s)
- {
- for(int i = 0 ; i < rows ; i ++)
- {
- for(int j = 0 ; j < columns ; j ++)
- {
- this->matrix[i][j]-=s.matrix[i][j];
- }
- }
- return *this;
- }
- Matrix operator*(Matrix &s)
- {
- Matrix newMatrix(this->rows,this->columns);
- for(int i = 0 ; i < rows ; i ++)
- {
- for(int j = 0 ; j < columns ; j ++)
- {
- for(int t = 0 ; t < columns ; t ++){
- newMatrix.matrix[i][j]+=this->matrix[i][t]*s.matrix[t][j];
- }
- }
- }
- return newMatrix;
- }
- friend ostream &operator <<(ostream &out ,const Matrix &s)
- {
- for(int i = 0 ; i < s.rows ; i ++)
- {
- for(int j = 0 ; j < s.columns ; j ++)
- {
- out<<s.matrix[i][j]<<" ";
- }
- out<<endl;
- }
- return out;
- }
- friend istream &operator >>(istream &in , Matrix &s)
- {
- in>>s.rows>>s.columns;
- for(int i = 0 ; i < s.rows ; i ++)
- {
- for(int j = 0 ; j < s.columns ; j ++)
- {
- in>>s.matrix[i][j];
- }
- }
- return in ;
- }
- };
- int main() {
- Matrix A,B,C;
- cin >> A >> B >> C;
- Matrix D = B * C;
- Matrix R = A - D + 2;
- cout << R;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement