Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- using namespace std;
- class Matrica{
- float a[10][10];
- int n;
- int m;
- public:
- Matrica(){};
- Matrica& operator=(const Matrica &mat){
- this->n = mat.n;
- this->m = mat.m;
- for(int i=0; i < n; i++){
- for(int j=0; j < m; j++){
- this->a[i][j] = mat.a[i][j];
- }
- }
- return *this;
- }
- Matrica operator*(Matrica &mat){
- Matrica t(*this);
- for(int i = 0; i < n; ++i){
- for(int j = 0; j < mat.m; ++j){
- float temp = 0;
- for(int k = 0; k < m; ++k){
- temp += a[i][k] * mat.a[k][j];
- }
- t.a[i][j] = temp;
- }
- }
- return t;
- }
- Matrica operator-(Matrica &mat){
- for(int i=0; i < n; i++){
- for(int j=0; j < m; j++){
- a[i][j] -= mat.a[i][j];
- }
- }
- return *this;
- }
- Matrica operator+(int num){
- for(int i=0; i < n; i++){
- for(int j=0; j < m; j++){
- a[i][j] += num;
- }
- }
- return *this;
- }
- friend istream &operator>>(istream &in, Matrica &mat){
- in >> mat.n >> mat.m;
- for(int i=0; i < mat.n; i++){
- for(int j=0; j < mat.m; j++){
- in >> mat.a[i][j];
- }
- }
- return in;
- }
- friend ostream &operator<<(ostream &o, const Matrica &mat){
- for(int i=0; i < mat.n; i++){
- for(int j=0; j < mat.m; j++){
- o << mat.a[i][j] << ' ';
- }
- o << endl;
- }
- return o;
- }
- };
- int main()
- {
- Matrica A,B,C;
- cin>>A>>B>>C;
- Matrica D=B*C;
- Matrica R=A-D+2;
- cout<<R;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement