Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class matrix{
- int row,col;
- double * arr;
- public:
- matrix(int r, int c);
- matrix(int r, int c, double *a);
- void print();
- bool tog(matrix other);
- double * get_arr(){ return arr; }
- matrix add(matrix other);
- matrix operator+ (matrix other);
- matrix dif(matrix other);
- matrix operator- (matrix other);
- };
- matrix::matrix(int r, int c){
- row=r;
- col=c;
- arr=new double[r*c];
- }
- matrix::matrix(int r, int c, double a[]){
- row=r;
- col=c;
- arr=new double[r*c];
- for(int i=0; i<r*c; i++)
- arr[i]=a[i];
- }
- void matrix::print(){
- for(int i=0; i<row; i++){
- for(int j=0; j<col; j++) cout << " " << *(arr + i*col + j);
- cout << endl;
- }
- }
- bool matrix::tog(matrix other) {
- return (row==other.row && col==other.col);
- }
- matrix matrix::operator+ (matrix other) { return this->add(other);}
- matrix matrix::add(matrix other){
- if (tog(matrix other)){
- double * other_arr=other.get_arr();
- double f[]=new double[row*col];
- for(int i=0; i<row*col; i++) f[i]=arr[i]+f[i];
- return matrix g(row,col,a);
- }
- }
- matrix matrix::operator- (matrix other) { return this->dif(other);}
- matrix matrix::dif(matrix other){
- if (tog(matrix other)){
- double * other_arr=other.get_arr();
- double s[]=new double[row*col];
- for(int i=0; i<row*col; i++) s[i]=arr[i]-s[i];
- return matrix e(row,col,a);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement