Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Matrix
#include <iostream> #include<matrix.h> class matrix { int r; int c; int **a; public: matrix(int,int); //constuctor matrix(const matrix&); //constructor to copy a matrix ~matrix(); //destructor //operator overloads matrix operator=(const matrix&); matrix operator+(const matrix&); matrix operator*(const matrix&); matrix operator+(const matrix&); void setValue(int r, int c); int getValue(int r, int c); }; matrix::matrix(int row, int col) { r=row; c=col; a=new int*[r]; for(int i=0;i<r;i++) { a[i]=new int*[c]; for(int j=0;j<c;j++) { a[i][j]=0; } } }; matrix::matrix(const matrix& m1) { r=m1.r; c=m2.c; a=new int*[r]; for(int i=0;i<r;i++) { a[i]=new int*[c]; for(int j=0;j<c;j++) { a[i][j]=m1.a[i][j]; } } } matrix::~matrix() { for(int i=0;i<r;i++) delete[] a[i]; delete a[]; } void matrix::setElement(int r, int c, int e) { array[r][c] = e; } int matrix::getValue(int r, int c) { return array[r][c]; } matrix matrix::operator=(const matrix& m1) { matrix m(r,c); for (int i=0; i<row; i++) { for (int j=0; j<col; j++) { m.a[i][j]=m1.a[i][j]; } } return m; } matrix matrix::operator+(const matrix& m1) { matrix m(r,c); for (int i=0; i<row; i++) { for (int j=0; j<col; j++) { m.a[i][j]=m1.a[i][j]+a[i][j]; } } return m; } matrix matrix::operator-(const matrix& m1) { matrix m(r,c); for (int i=0; i<row; i++) { for (int j=0; j<col; j++) { m.a[i][j]=a[i][j]-m1[i][j]; } } return m; } matrix matrix::operator*(const matrix& m) { matrix m(row,col); for (int i=0; i<row; i++) { for (int j=0; j<col; j++) { for(int k = 0; k < col; ++k) { m.a[i][j] += a[i][k] * m.a[k][j]; } } } return m; }
run
|
edit
|
history
|
help
0
DailyGroceryHisto
XD
My First Wall
Count squares
CountingSort
Pac update
fastest input taking for large files
BinSearch
12535
VecCrossProd