#include<iostream.h>
#include<conio.h>
class Matrix
{
int arr[2][2],i,j;
public:
void get_matrix()
{
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<"\n Enter element =>";
cin>>arr[i][j];
}
}
}
void disp_matrix()
{
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<arr[i][j]<<" ";
}
cout<<"\n";
}
}
void operator +(Matrix temp)
{
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<arr[i][j]+temp.arr[i][j]<<"\t";
}
cout<<"\n";
}
}
void operator -(Matrix temp)
{
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
cout<<arr[i][j]-temp.arr[i][j]<<"\t";
}
cout<<"\n";
}
}
};
int main()
{
Matrix m1,m2;
clrscr();
cout<<"\n Enter first matrix ";
m1.get_matrix();
cout<<"\n Enter second matrix ";
m2.get_matrix();
cout<<"\n 1st matrix is \n";
m1.disp_matrix();
cout<<"\n 2nd matrix is \n";
m2.disp_matrix();
cout<<"\n Addition of matrix is \n";
m1+m2;//m1.(m2)
cout<<"\n Subtraction of matrix is \n";
m1-m2;
getch();
return 0;
}
Leave a Reply