Advertisement
Guest User

[C++]template class square matrix

a guest
Jun 10th, 2012
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. template<class T>
  2. typedef struct macierz{
  3.  
  4.         T Rekord;
  5.         int wysokoscMacierzyKwadratowej;
  6.  
  7.     void MacierzNowa(int wysokosc){
  8.         MacierzUsun();
  9.         wysokoscMacierzyKwadratowej = wysokosc;
  10.  
  11.         Rekord = new T *[wysokoscMacierzyKwadratowej];
  12.         for(int i(0); i<wysokoscMacierzyKwadratowej; i++)
  13.             Rekord[i] = **new T[wysokoscMacierzyKwadratowej];**
  14.         MacierzResetuj();
  15.     }
  16.  
  17.     void MacierzUsun(){
  18.     if(Rekord != NULL){
  19.         for(int i(0); i< wysokoscMacierzyKwadratowej; i++)
  20.             delete Rekord[i];
  21.         delete Rekord;
  22.         Rekord = NULL;
  23.     }}
  24.  
  25.     void MacierzResetuj(){
  26.         for(int i(0) ; i < wysokoscMacierzyKwadratowej ; i++ )
  27.             for(int j(0) ; j < wysokoscMacierzyKwadratowej ; j++)
  28.             Rekord[i][j] = 0;
  29.     }
  30.  
  31.     void MacierzZapisz(T wartosc, int wiersz, int kolumna){
  32.         Rekord[wiersz][kolumna] = wartosc;
  33.     }
  34.  
  35.     T SumaWiersza(int wiersz){
  36.         T suma(0);
  37.         for(int i(0); i < wysokoscMacierzyKwadratowej; i++)
  38.         suma+=Rekord[wiersz][i];
  39.     return suma;
  40.     }
  41.  
  42.     T SumaMacierzy(){
  43.         T suma(0);
  44.         for(int i(0), i < wysokoscMacierzyKwadratowej; i++)
  45.             suma+=SumaWiersza(i);
  46.     return suma;
  47.     }
  48. };
  49.  
  50.  
  51.  
  52. template<class T>::macierz(){
  53.         wysokoscMacierzyKwadratowej = 0;
  54.         Rekord = NULL;
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement