I ave made a program for matrix addition using operator overloading. I have made the program but it is not taking input for matrix B. Please look at the program and help. In this the matrix inputs are noramlly taken in main with two different objects, then i have used operator overloading for '+' to add 2 object members, ten for displaying also '<<' operator is overloaded.
#include<iostream>
using namespace std;
int s;
class matrix
{
public:
int **m1,**m;
friend matrix operator +(matrix &t,matrix &t1);
friend ostream& operator << (ostream &out,matrix &t);
};
matrix operator +(matrix &t,matrix &t1)
{
for(int x=0;x<s;x++)
{
for(int y=0;y<s;y++)
{
t.m1[x][y]+=t1.m1[x][y];
}
}
}
ostream& operator << (ostream &out,matrix &t2)
{
for(int p=0;p<s;p++)
{
for(int q=0;q<s;q++)
{
out<<t2.m[p][q]<<" ";
}
out<<endl;
}
}
int main()
{
cout<<"Enter the size of matrices(SQUARE MAT ONLY):: ";
cin>>s;
matrix t,t1,t2;
for(int i=0;i<s;i++)
{
for(int j=0;j<s;j++)
{
cout<<"Enter value ("<<i+1<<","<<j+1<<") for matrix A::";
cin>>t.m1[i][j];
}
}
for(int i=0;i<s;i++)
{
for(int j=0;j<s;j++)
{
cout<<"Enter value ("<<i+1<<","<<j+1<<") for matrix B::";
cin>>t1.m1[i][j];
}
}
t2=t+t1;
cout<<t2;
}