Advertisement
metalni

OOP Labs 5 Matrica

May 30th, 2020
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.04 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3.  
  4. using namespace std;
  5.  
  6. //vashiot kod ovde
  7. class Matrica{
  8.     private:
  9.         float mat[10][10];
  10.         int red;
  11.         int kol;
  12.     public:
  13.         Matrica(){
  14.             this->red = 0;
  15.             this->kol = 0;
  16.             for(int i=0; i<10; i++){
  17.                 for(int j=0; j<10; j++){
  18.                     this->mat[i][j] = 0;
  19.                 }
  20.             }
  21.         }
  22.  
  23.         friend istream & operator >> (istream &input,  Matrica &m){
  24.             input >> m.red;
  25.             input >> m.kol;
  26.             for(int i=0; i<m.red; i++){
  27.                 for(int j=0; j<m.kol; j++){
  28.                    input >> m.mat[i][j];
  29.                 }    
  30.             }
  31.             return input;
  32.         }
  33.  
  34.         friend ostream & operator << (ostream &output, Matrica &m){
  35.             for(int i=0; i<m.red; i++){
  36.                 for(int j=0; j<m.kol; j++){
  37.                    cout << m.mat[i][j] << " ";
  38.                 }
  39.                 cout << "\n";
  40.             }
  41.             return output;
  42.         }
  43.  
  44.         Matrica operator+(const int n){
  45.             for(int i=0; i<this->red; i++){
  46.                 for(int j=0; j<this->kol; j++){
  47.                     this->mat[i][j] += n;
  48.                 }
  49.             }
  50.             return *this;
  51.         }
  52.  
  53.         Matrica operator-(const Matrica &m){
  54.             for(int i=0; i<this->red; i++){
  55.                 for(int j=0; j<this->kol; j++){
  56.                     this->mat[i][j] -= m.mat[i][j];
  57.                 }
  58.             }
  59.             return *this;
  60.         }
  61.  
  62.         Matrica operator*(const Matrica &m){
  63.             Matrica temp;
  64.             for(int i=0; i<this->red; i++){
  65.                 for(int j=0; j<this->kol; j++){
  66.                     for(int k=0; k<this->red; k++)
  67.                         temp.mat[i][j]+= this->mat[i][k] * m.mat[k][j];
  68.                 }
  69.             }
  70.             return temp;
  71.         }
  72. };
  73.  
  74.  
  75. //main
  76. int main()
  77. {
  78.     Matrica A,B,C;
  79.     cin>>A>>B>>C;
  80.     Matrica D=B*C;
  81.     Matrica R=A-D+2;
  82.     cout<<R;
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement