Написание программы, демонстрирующей работу с классом, страница 2

                  TMatr c(c,r);

                  for (int i=0;i<c.r;i++){

                                    for (int j=0;j<c.c;j++){

                                                     c.a[i][j]=a[i][j]-b.a[i][j];

                                    }

                  }

                  return c;

}

TMatr TMatr::operator*(TMatr b){

                  TMatr k(c,r);

                  double sum=0;

                  for (int i=0;i<r;i++){

                                    for (int j=0;j<c;j++){

                                                     for (int l=0;l<c;l++){

                                                                       sum+=a[i][l]*b.a[l][j];

                                                     }

                                                     k.a[i][j]=sum;

                                                     sum=0;

                                    }

                  }

                  return k;   

}

TMatr TMatr::operator^(int b){

                  TMatr k(c,r),f(c,r);

                  for (int i=0;i<r;i++){

                                    for (int j=0;j<c;j++){

                                                     k.a[i][j]=a[i][j];

                                                     f.a[i][j]=a[i][j];

                                    }

                  }

                  if (b>1){

                                    for (int i=0;i<b-1;i++){

                                                     k=k*f;

                                    }

                                    return k;

                  }else if (b==1) return k;

                  else if (b==0){

                                    for (int i=0;i<k.r;i++){

                                                     for (int j=0;j<k.c;j++){

                                                                       k.a[i][j]=0;

                                                     }}

                                    for (int i=0;i<k.r;i++)

                                                     k.a[i][i]=1;

                                    return k;

                  }else if (b<0){

                                    for (int i=0;i<abs(b)-1;i++){

                                                     k=k*f;

                                    }

                                    for (int i=0;i<r;i++){

                                                     for (int j=0;j<c;j++){

                                                                       k.a[i][j]=1/k.a[i][j];

                                                     }

                                    }

                                    return k;

                  }

}

TMatr TMatr::operator/(TMatr b){

                  TMatr k(c,r);

                  for (int i=0;i<r;i++){

                                    for (int j=0;j<c;j++){

                                                     k.a[i][j]=a[i][j];

                                    }

                  }

                  k=k^-1;

                  k=k*b;

                  return k;

}

TMatr TMatr::operator*=(double b){

                  TMatr k(c,r);

                  for (int i=0;i<r;i++){

                                    for (int j=0;j<c;j++){

                                                     k.a[i][j]=a[i][j];

                                    }

                  }

                  for (int i=0;i<r;i++){

                                    for (int j=0;j<c;j++){

                                                     a[i][j]=a[i][j]*b;

                                    }

                  }

                  return k;

}

TMatr TMatr::operator/=(double b){

                  TMatr k(c,r);

                  for (int i=0;i<r;i++){

                                    for (int j=0;j<c;j++){

                                                     k.a[i][j]=a[i][j];

                                    }

                  }

                  for (int i=0;i<r;i++){

                                    for (int j=0;j<c;j++){

                                                     a[i][j]=a[i][j]/b;

                                    }

                  }

                  return k;

}

bool TMatr::operator==(TMatr b){

                  bool res=true;

                  for (int i=0;i<r;i++){

                                    for (int j=0;j<c;j++){

                                                     if (a[i][j]!=b.a[i][j])

                                                                       res=false;

                                    }

                  }

                  return res;

}

void TMatr::TransMatr(){

                  TMatr k(r,c);

                  for (int i=0;i<r;i++){

                                    for (int j=0;j<c;j++){

                                                     k.a[j][i]=a[i][j];

                                    }

                  }

                  for (int i=0;i<r;i++){

                                    for (int j=0;j<c;j++){

                                                     a[i][j]=k.a[i][j];

                                    }

                  }

}

void TMatr::MatrNorm(){

                  double norm=0,sum=0;

                  for (int i=0;i<r;i++){

                                    for (int j=0;j<c;j++){

                                                     sum+=abs(a[j][i]);

                                    }

                                    if (sum>norm) {

                                                     norm=sum;

                                                     sum=0;

                                    }else sum=0;

                  }

                  cout<<"Norm of the matrix is "<<norm<<endl;