Advertisement
frusso1337

MATRICA C++

Apr 2nd, 2018
384
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.29 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstring>
  3. using namespace std;
  4. class Matrica{
  5. private:
  6. float matrix[10][10];
  7. int rows;
  8. int columns;
  9. public:
  10. Matrica(){}
  11. Matrica(int rows,int columns){
  12. this->rows=rows;
  13. this->columns=columns;
  14. for(int i=0;i<rows;i++){
  15. for(int j=0;j<columns;j++){
  16. this->matrix[i][j]=0;
  17. }
  18. }
  19. }
  20. friend istream& operator>>(istream &input,Matrica &m){
  21. input>>m.rows>>m.columns;
  22. for(int i=0;i<m.rows;i++){
  23. for(int j=0;j<m.columns;j++){
  24. input>>m.matrix[i][j];
  25. }
  26. }
  27. return input;
  28. }
  29. friend ostream& operator<<(ostream &output,Matrica &m){
  30. for(int i=0;i<m.rows;i++){
  31. for(int j=0;j<m.columns;j++){
  32. output<<m.matrix[i][j]<<" ";
  33. }
  34. output<<endl;
  35. }
  36. return output;
  37. }
  38. Matrica& operator+(int a){
  39. for(int i=0;i<rows;i++){
  40. for(int j=0;j<columns;j++){
  41. matrix[i][j]+=a;
  42. }
  43. }
  44. return *this;
  45. }
  46. Matrica& operator-(Matrica &b){
  47. for(int i=0;i<rows;i++){
  48. for(int j=0;j<columns;j++){
  49. this->matrix[i][j]-=b.matrix[i][j];
  50. }
  51. }
  52. return *this;
  53. }
  54. Matrica operator*(Matrica &b){
  55. Matrica newmatrica(this->rows,this->columns);
  56. for(int i=0;i<rows;i++){
  57. for(int j=0;j<columns;j++){
  58. for(int k=0;k<columns;k++){
  59. newmatrica.matrix[i][j]+=this->matrix[i][k]*b.matrix[k][j];
  60. }
  61. }
  62. }
  63. return newmatrica;
  64. }
  65. };
  66. int main()
  67. {
  68. Matrica A,B,C;
  69. cin>>A>>B>>C;
  70. Matrica D=B*C;
  71. Matrica R=A-D+2;
  72. cout<<R;
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement