Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cstdlib>
- #include <boost/thread/thread.hpp>
- #define parity(x) (1-(x%2)*2)
- using namespace std;
- class Macierz {
- private:
- int rows, cols;
- int **tab;
- public:
- Macierz()
- {
- rows=0;
- cols=0;
- tab[0][0]=1;};
- Macierz & operator* ( Macierz &q)
- {
- static Macierz temp(getRows(),q.getCols());
- if(getCols() == q.getRows())
- {
- for(int i=0;i<getRows();++i)
- for(int j=0;j<q.getCols();++j)
- for(int k=0;k<getCols();++k)
- temp.setValue(temp.at(i,j)+at(i,k)*q.at(k,j),i,j);
- return temp;
- }
- else return q;
- };
- int determine;
- Macierz(int rows,int cols)
- {
- this->rows=rows;
- this->cols=cols;
- int (**tab) = new int *[rows];
- for(int i=0;i<rows;++i)
- tab[i] = new int [cols];
- for(int i=0;i<rows;++i)
- for(int j=0;j<cols;++j)
- if(i==j) tab[i][j]=1;
- else tab[i][j]==0;
- this->tab=tab;
- }
- ~Macierz()
- {
- for(int i=0;i<cols;++i) delete [] tab[i];
- delete [] tab;
- }
- void setSize(int rows,int cols)
- {
- this->rows=rows;
- this->cols=cols;
- Macierz(rows,cols);
- }
- void generateRandom(int n)
- {
- for(int i=0;i<this->rows;++i)
- for(int j=0;j<cols;++j)
- tab[i][j]= (rand() % n);
- }
- Macierz Minor(int row, int col)
- {
- Macierz temp(rows-1,cols-1);
- for(int i=0;i<rows-1;++i)
- for(int j=0;j<cols-1;++j)
- temp.setValue(at(i < row ? i : i+1,j < col ? j : j+1),i,j);
- return temp;
- }
- int det()
- {
- if(rows == cols && rows == 1) return at(0,0);
- else {
- int X=0;
- for(int i=0;i<rows;i++)
- {
- X=X+(Minor(i,0).det())*at(i,0)*parity(i+0);
- }
- determine=X;
- return X;
- }
- }
- Macierz& operator=(Macierz const &q) {
- if (this != &q) {
- delete tab; // free resource;
- tab = 0;
- tab = q.tab;
- rows=q.rows;
- cols=q.cols;
- }
- return *this;
- };
- Macierz& operator+ ( Macierz &q) {
- static Macierz temp(q.getRows(),q.getCols());
- if(q.getRows()==getRows() && q.getCols()==getCols() )
- {
- for(int i=0;i<q.getRows();++i)
- for(int j=0;j<q.getCols();++j)
- temp.setValue(q.at(i,j)+at(i,j),i,j);
- return temp;
- }
- else
- return q;
- };
- Macierz& operator- ( Macierz &q) {
- static Macierz temp(q.getRows(),q.getCols());
- if(q.getRows()==getRows() && q.getCols()==getCols() ) {
- for(int i=0;i<q.getRows();++i)
- for(int j=0;j<q.getCols();++j)
- temp.setValue(q.at(i,j)-at(i,j),i,j);
- return temp;
- }
- else
- return q;
- };
- int at(int row, int col)
- {
- if(row>rows || col > cols)
- {
- cout << "index excedes the size of matrix!" << endl ;
- return 666;
- }
- else return tab[row][col];
- }
- int getCols()
- {
- return cols;
- }
- int getRows()
- {
- return rows;
- }
- void setValue(int value,int row,int col)
- {
- tab[row][col]=value;
- }
- };
- ostream & operator<< (ostream &wyjscie, Macierz &s)
- {
- for(int i=0;i< s.getRows();++i)
- {
- for(int j=0;j<s.getCols();++j)
- {
- wyjscie << s.at(i,j) << ", ";
- }
- wyjscie << ";" << endl ;
- }
- wyjscie << endl ;
- return wyjscie;
- }
Add Comment
Please, Sign In to add comment