Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Matrica {
- private:
- float m[10][10];
- int r;
- int c;
- public:
- Matrica() {
- r = 0;
- c = 0;
- for(int i = 0; i < 10; ++i) {
- for(int j = 0; j < 10; ++j)
- m[i][j] = 0;
- }
- }
- Matrica operator +(int const &n) {
- Matrica t;
- t.r = r;
- t.c = c;
- for(int i = 0; i < r; ++i) {
- for(int j = 0; j < c; ++j)
- t.m[i][j] = m[i][j] + n;
- }
- return t;
- }
- Matrica operator -(const Matrica &x) {
- Matrica t;
- t.r = x.r;
- t.c = x.c;
- for(int i = 0; i < x.r; ++i) {
- for(int j = 0; j < x.c; ++j)
- t.m[i][j] = m[i][j] - x.m[i][j];
- }
- return t;
- }
- Matrica operator *(const Matrica &x) {
- Matrica t;
- t.r = x.r;
- t.c = x.c;
- for(int i = 0; i < x.r; ++i) {
- for(int j = 0; j < x.c; ++j) {
- float tmp = 0;
- for(int k = 0; k < x.r; ++k)
- tmp += m[i][k] * x.m[k][j];
- t.m[i][j] = tmp;
- }
- }
- return t;
- }
- friend istream& operator>>( istream& in, Matrica& x );
- friend ostream& operator<<( ostream& out, Matrica& x );
- };
- istream& operator>>( istream& in, Matrica& x )
- {
- in >> x.r;
- in >> x.c;
- for(int i=0; i<x.r; i++)
- for(int j=0; j<x.c; j++)
- in >> x.m[i][j];
- return in;
- }
- ostream& operator<<( ostream& out, Matrica& x )
- {
- for(int i=0; i<x.r; i++)
- {
- for( int j=0; j<x.c; j++)
- out<<x.m[i][j]<<" ";
- out<<endl;
- }
- return out;
- }
- 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