Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <cstring>
- using namespace std;
- class Matrica{
- private:
- float matrix[10][10];
- int rows;
- int columns;
- public:
- Matrica(){}
- Matrica(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;
- }
- }
- }
- friend istream& operator>>(istream &input,Matrica &m){
- input>>m.rows>>m.columns;
- for(int i=0;i<m.rows;i++){
- for(int j=0;j<m.columns;j++){
- input>>m.matrix[i][j];
- }
- }
- return input;
- }
- friend ostream& operator<<(ostream &output,Matrica &m){
- for(int i=0;i<m.rows;i++){
- for(int j=0;j<m.columns;j++){
- output<<m.matrix[i][j]<<" ";
- }
- output<<endl;
- }
- return output;
- }
- Matrica& operator+(int a){
- for(int i=0;i<rows;i++){
- for(int j=0;j<columns;j++){
- matrix[i][j]+=a;
- }
- }
- return *this;
- }
- Matrica& operator-(Matrica &b){
- for(int i=0;i<rows;i++){
- for(int j=0;j<columns;j++){
- this->matrix[i][j]-=b.matrix[i][j];
- }
- }
- return *this;
- }
- Matrica operator*(Matrica &b){
- Matrica newmatrica(this->rows,this->columns);
- for(int i=0;i<rows;i++){
- for(int j=0;j<columns;j++){
- for(int k=0;k<columns;k++){
- newmatrica.matrix[i][j]+=this->matrix[i][k]*b.matrix[k][j];
- }
- }
- }
- return newmatrica;
- }
- };
- int main()
- {
- Matrica A,B,C;
- cin>>A>>B>>C;
- Matrica D=B*C;
- Matrica R=A-D+2;
- cout<<R;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement