Write a C++ Program for Matrix Addition by Overloading + operator
//Matrix Addition by Overloading + operator
#include
#include
class matadd
{
int **a;
int row,col;
public:
matadd(){}
matadd(int r,int c);
void getdata(void);
void display(void);
matadd operator + (matadd o2);
};
matadd :: matadd(int r,int c)
{
row=r;
col=c;
a=new int *[row];
for(int i=0;i
}
}
void matadd :: display(void)
{
cout<<"\n\n\nMatrix Display\n\n";
for(int i=0;i
{
for(int j=0;j
cout<<<" ";
cout<
}
}
matadd matadd :: operator + (matadd o2)
{
matadd temp(row,col);
for(int i=0;i
{
for(int j=0;j
{
temp.a[i][j]=a[i][j] + o2.a[i][j];
}
}
return temp;
}
void main()
{
clrscr();
matadd o1(3,2),o2(3,2),o3;
o1.getdata();
o2.getdata();
o3=o1+o2;
o3.display();
getch();
}