Advertisement
Guest User

Untitled

a guest
Mar 29th, 2015
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.11 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. class Matrica
  5. {
  6.     private:
  7.     float matr[10][10];
  8.     int red;
  9.     int kol;
  10.     public:
  11.    
  12.     Matrica()
  13.     {
  14.         red = 0;
  15.         kol = 0;
  16.         for(int i=0;i<10;i++ )
  17.             for(int j=0;j<10;j++)
  18.             matr[i][j] = 0;
  19.     }
  20.    
  21.     Matrica operator+(Matrica const& mat)
  22.     {
  23.         Matrica tp;
  24.         tp.red = mat.red;
  25.         tp.kol = mat.kol;
  26.         for(int i=0;i<mat.red;i++)
  27.             for(int j=0;j<mat.kol;j++ )
  28.             tp.matr[i][j] = mat.matr[i][j] + matr[i][j];
  29.             return tp;
  30.     }
  31.    
  32.     Matrica operator-( Matrica const& mat )
  33.     {
  34.         Matrica tp;
  35.         tp.red = mat.red;
  36.         tp.kol = mat.kol;
  37.         for(int i=0;i<mat.red;i++)
  38.             for(int j=0;j<mat.kol;j++)
  39.             tp.matr[i][j] = matr[i][j] - mat.matr[i][j];
  40.             return tp;
  41.     }
  42.    
  43.     Matrica operator*( Matrica const& mat)
  44.     {
  45.         Matrica tp;
  46.         tp.red = mat.red;
  47.         tp.kol = mat.kol;
  48.         for(int i=0;i<mat.red;i++)
  49.             for(int j=0;j<mat.kol;j++)
  50.         {
  51.             float v=0;
  52.             for(int x=0;x<mat.red;x++)
  53.                 v += matr[i][x] * mat.matr[x][j];
  54.             tp.matr[i][j]=v;
  55.         }
  56.         return tp;
  57.     }
  58.    
  59.     Matrica operator+( int const& broj )
  60.     {
  61.         Matrica tp;
  62.         tp.red=red;
  63.         tp.kol=kol;
  64.         for(int i=0;i<red;i++)
  65.             for(int j=0;j<kol;j++)
  66.             tp.matr[i][j] = matr[i][j] + broj;
  67.             return tp;
  68.     }
  69.     friend istream& operator>>( istream& in, Matrica& mat );
  70.     friend ostream& operator<<( ostream& out, Matrica& mat );
  71. };
  72.  
  73. istream& operator>>( istream& in, Matrica& mat )
  74. {
  75. in >> mat.red;
  76. in >> mat.kol;
  77. for(int i=0;i<mat.red;i++)
  78. for(int j=0;j<mat.kol;j++)
  79. in >> mat.matr[i][j];
  80. return in;
  81. }
  82.  
  83. ostream& operator<<( ostream& out, Matrica& mat )
  84. {
  85. for(int i=0;i<mat.red;i++)
  86. {
  87. for( int j=0;j<mat.kol;j++)
  88. out<<mat.matr[i][j]<<" ";
  89. out<<endl;
  90. }
  91. return out;
  92. }
  93.  
  94. int main()
  95. {
  96. Matrica A,B,C;
  97. cin>>A>>B>>C;
  98. Matrica D=B*C;
  99. Matrica R=A-D+2;
  100. cout<<R;
  101. return 0;
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement