Hadix

Macierz.h solver

Jun 5th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.68 KB | None | 0 0
  1. #pragma once
  2. #include <iomanip>
  3. #include <iostream>
  4. #include <exception>
  5. #include <fstream>
  6. #include <vector>
  7. #include <string>
  8. #include <algorithm>
  9. #include <iterator>
  10. #include <cstring>
  11. template <typename T>
  12. class Macierz {
  13.     int ile_wierszy;
  14.     int dlugosc_wiersza;
  15.     //double dane[3*4];
  16.     //double * wiersze[3];
  17.     T *dane;
  18.     T **wiersze;
  19.  
  20. public:
  21. ~Macierz() {
  22.     delete[] wiersze;
  23.     delete[] dane;
  24. }
  25. Macierz(int _x) {
  26.     ile_wierszy = _x;
  27.     dlugosc_wiersza = _x + 1;
  28.     alokuj(_x);
  29. }
  30.   // Usuniety konstruktor kopiujacy i operator przypisania powoduje,
  31.   // ze obiektow tej klasy nie da sie przekazywac przez wartosc.
  32.   // Jest to rowniez sposob dotrzymania zasady trzech.
  33. void operator=(const Macierz& other_) = delete;
  34. Macierz(const Macierz& other_) = delete;
  35. void zeruj() {
  36.       for (int i = 0; i < ile_wierszy*dlugosc_wiersza; ++i) {
  37.           dane[i] = 0;
  38.       }
  39.   }
  40. int getIleWierszy() { return ile_wierszy; }
  41. T& element(int i, int j) {
  42.     if (i >= ile_wierszy || j >= dlugosc_wiersza || i<0 || j<0) throw 1;
  43.     return wiersze[i][j];
  44.   }
  45. T& wolny(int i) {
  46.     return wiersze[i][dlugosc_wiersza - 1];
  47.   }
  48. void alokuj(int x) {
  49.     if (x <= 0) throw 3;
  50.     dane = new T[x*(x + 1)];
  51.     wiersze = new T*[x];
  52.         for (int i = 0; i < x; i++) {
  53.              wiersze[i] = dane + (i * (x+1));
  54.          }
  55.      
  56.  }
  57. void pokaz() const {
  58.      using std::cout;
  59.      using std::endl;
  60.      using std::setw;
  61.      using std::fixed;
  62.      using std::setprecision;
  63.      for (int i = 0; i < ile_wierszy; ++i) {
  64.          for (int j = 0; j < dlugosc_wiersza - 1; ++j) {
  65.              cout << setw(8) << setprecision(4) << fixed << wiersze[i][j];
  66.          }
  67.          cout << "  |" << setw(8) << setprecision(4) << wiersze[i][dlugosc_wiersza - 1] << endl;
  68.      }
  69.  }
  70. };
Add Comment
Please, Sign In to add comment