-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path9.cpp
More file actions
43 lines (39 loc) · 946 Bytes
/
9.cpp
File metadata and controls
43 lines (39 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <iostream>
using namespace std;
class Matrix {
int mat[10][10];
int row, col;
public:
void input() {
cout << "Enter no of rows and columns: ";
cin >> row >> col;
cout << "Enter elements: "<<endl;
for (int i = 0; i < row; i++)
for (int j = 0; j < col; j++)
cin >> mat[i][j];
}
void display() {
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++)
cout << mat[i][j] << " ";
cout << "\n";
}
}
Matrix operator+(const Matrix& m) {
Matrix q;
q.row = row;
q.col = col;
for (int i = 0; i < row; i++)
for (int j = 0; j < col; j++)
q.mat[i][j] = mat[i][j] + m.mat[i][j];
return q;
}
};
int main() {
Matrix m1, m2, s;
m1.input();
m2.input();
s = m1 + m2;
cout << "Sum : "<<endl;
s.display();
}