Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <iomanip>
- #include <iostream>
- #include <exception>
- #include <fstream>
- #include <vector>
- #include <string>
- #include <algorithm>
- #include <iterator>
- #include <cstring>
- template <typename T>
- class Macierz {
- int ile_wierszy;
- int dlugosc_wiersza;
- //double dane[3*4];
- //double * wiersze[3];
- T *dane;
- T **wiersze;
- public:
- ~Macierz() {
- delete[] wiersze;
- delete[] dane;
- }
- Macierz(int _x) {
- ile_wierszy = _x;
- dlugosc_wiersza = _x + 1;
- alokuj(_x);
- }
- // Usuniety konstruktor kopiujacy i operator przypisania powoduje,
- // ze obiektow tej klasy nie da sie przekazywac przez wartosc.
- // Jest to rowniez sposob dotrzymania zasady trzech.
- void operator=(const Macierz& other_) = delete;
- Macierz(const Macierz& other_) = delete;
- void zeruj() {
- for (int i = 0; i < ile_wierszy*dlugosc_wiersza; ++i) {
- dane[i] = 0;
- }
- }
- int getIleWierszy() { return ile_wierszy; }
- T& element(int i, int j) {
- if (i >= ile_wierszy || j >= dlugosc_wiersza || i<0 || j<0) throw 1;
- return wiersze[i][j];
- }
- T& wolny(int i) {
- return wiersze[i][dlugosc_wiersza - 1];
- }
- void alokuj(int x) {
- if (x <= 0) throw 3;
- dane = new T[x*(x + 1)];
- wiersze = new T*[x];
- for (int i = 0; i < x; i++) {
- wiersze[i] = dane + (i * (x+1));
- }
- }
- void pokaz() const {
- using std::cout;
- using std::endl;
- using std::setw;
- using std::fixed;
- using std::setprecision;
- for (int i = 0; i < ile_wierszy; ++i) {
- for (int j = 0; j < dlugosc_wiersza - 1; ++j) {
- cout << setw(8) << setprecision(4) << fixed << wiersze[i][j];
- }
- cout << " |" << setw(8) << setprecision(4) << wiersze[i][dlugosc_wiersza - 1] << endl;
- }
- }
- };
Add Comment
Please, Sign In to add comment