Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Matrix
- {
- public:
- int matrix[3][3];
- Matrix(int m[3][3])
- {
- for(int i=0;i<3;i++)
- {
- for(int j=0;j<3;j++)
- {
- matrix[i][j] = m[i][j] ;
- }
- }
- }
- void show()
- {
- for(int i=0;i<3;i++)
- {
- for(int j=0;j<3;j++)
- {
- cout << matrix[i][j] << " " ;
- }
- cout << endl ;
- }
- }
- void operator+(Matrix &m)
- {
- for(int i=0;i<3;i++)
- {
- for(int j=0;j<3;j++)
- {
- cout << matrix[i][j]+m.matrix[i][j] << " " ;
- }
- cout << endl ;
- }
- }
- void operator-(Matrix &m)
- {
- for(int i=0;i<3;i++)
- {
- for(int j=0;j<3;j++)
- {
- cout << matrix[i][j]-m.matrix[i][j] << " " ;
- }
- cout << endl ;
- }
- }
- };
- int main(void)
- {
- int a[3][3] = {{2,2,2},{2,2,2},{2,2,2}};
- int b[3][3] = {{1,1,1},{1,1,1},{1,1,1}};
- Matrix m1(a), m2(b);
- cout << "m1:" << endl;
- m1.show() ;
- cout << "m2:" << endl;
- m2.show() ;
- cout << "m1+m2:" << endl;
- m1+m2 ;
- cout << "m1-m2:" << endl;
- m1-m2 ;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement