Advertisement
Guest User

Untitled

a guest
May 25th, 2015
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.59 KB | None | 0 0
  1. class matrix{
  2. int row,col;
  3. double * arr;
  4. public:
  5. matrix(int r, int c);
  6. matrix(int r, int c, double *a);
  7. void print();
  8. bool tog(matrix other);
  9. double * get_arr(){ return arr; }
  10. matrix add(matrix other);
  11. matrix operator+ (matrix other);
  12. matrix dif(matrix other);
  13. matrix operator- (matrix other);
  14.  
  15. };
  16. matrix::matrix(int r, int c){
  17. row=r;
  18. col=c;
  19. arr=new double[r*c];
  20. }
  21. matrix::matrix(int r, int c, double a[]){
  22. row=r;
  23. col=c;
  24. arr=new double[r*c];
  25. for(int i=0; i<r*c; i++)
  26. arr[i]=a[i];
  27. }
  28. void matrix::print(){
  29. for(int i=0; i<row; i++){
  30. for(int j=0; j<col; j++) cout << " " << *(arr + i*col + j);
  31. cout << endl;
  32. }
  33. }
  34. bool matrix::tog(matrix other) {
  35. return (row==other.row && col==other.col);
  36. }
  37. matrix matrix::operator+ (matrix other) { return this->add(other);}
  38. matrix matrix::add(matrix other){
  39. if (tog(matrix other)){
  40. double * other_arr=other.get_arr();
  41. double f[]=new double[row*col];
  42. for(int i=0; i<row*col; i++) f[i]=arr[i]+f[i];
  43. return matrix g(row,col,a);
  44. }
  45. }
  46. matrix matrix::operator- (matrix other) { return this->dif(other);}
  47. matrix matrix::dif(matrix other){
  48. if (tog(matrix other)){
  49. double * other_arr=other.get_arr();
  50. double s[]=new double[row*col];
  51. for(int i=0; i<row*col; i++) s[i]=arr[i]-s[i];
  52. return matrix e(row,col,a);
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement