#include<iostream.h>
#include<conio.h>
class Matrix
{
int a[3][3];
public:
void accept()
{
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
{
cout<<endl<<"Enter a value for ["<<i+1<<"]["<<j+1<<"]: ";
cin>>a[i][j];
}
}
void display()
{
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
}
Matrix operator+(Matrix m)
{
Matrix temp;
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
temp.a[i][j]=a[i][j]+m.a[i][j];
return temp;
}
};//End of class
int main()
{
Matrix m1,m2,m3;
clrscr();
cout<<endl<<"Enter Matrix1: ";
m1.accept();
cout<<endl<<"Enter Matrix2: ";
m2.accept();
m3=m1+m2;
cout<<endl<<"Matrix1 is:"<<endl;
m1.display();
cout<<endl<<"Matrix2 is:"<<endl;
m2.display();
cout<<endl<<"Matrix3 = Matrix1 + Matrix2 is:"<<endl;
m3.display();
getch();
return 0;
}
Post a Comment