-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathq9.cpp
69 lines (67 loc) · 1.06 KB
/
q9.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <iostream>
using namespace std;
class matrix
{
int arr[3][3];
public:
void read()
{
cout<<"enter matrix:";
for (int row=0;row<3;row++)
for (int col=0;col<3;col++)
cin>>arr[row][col];
}
void print()
{
cout<<"Matrix is: "<<endl;
for (int row=0;row<3;row++)
{
for (int col=0;col<3;col++)
{
cout<<arr[row][col]<<" ";
}
cout<<endl;
}
}
matrix operator +(matrix c)
{
matrix obj;
for (int row=0;row<3;row++)
{
for (int col=0;col<3;col++)
{
obj.arr[row][col] = arr[row][col] + c.arr[row][col] ;
}
}
return obj;
}
matrix operator -(matrix c)
{
matrix obj;
for (int row=0;row<3;row++)
{
for (int col=0;col<3;col++)
{
obj.arr[row][col] = arr[row][col] - c.arr[row][col] ;
}
}
return obj;
}
};
int main()
{
matrix obj1,obj2,add,sub;
obj1.read();
obj2.read();
cout<<"first ";
obj1.print();
cout<<endl<<"second ";
obj2.print();
add = obj1 + obj2;
cout<<"After addition:"<<endl;
add.print();
sub = obj1 - obj2;
cout<<endl<<"After subtraction:"<<endl;
sub.print();
return 0;
}