0

Well I'm relatively new to the forums and to C++. I'd like to overload + and = to add two matrices by being able to use Z=X+Y format.

Header file:

```
#ifndef HOMEWORK1_H
#define HOMEWORK1_H
class Matrix{
public:
double **element;
Matrix(int=3,int=3);
~Matrix();
double getelement(int,int);
void setelement(int, int,double);
Matrix & operator+(const Matrix &, const Matrix &);
Matrix & operator=(const Matrix & );
private:
int r;
int c;
};
#endif
```

Implementation code for operator+:

```
Matrix & Matrix::operator+( const Matrix& s, const Matrix& t) //overloaded +
{
Matrix temp(3,3);
for (int r=0;r<3;r++)
for (int c=0;c<3;c++)
{
temp(r,c)=s.getelement(r,c)+ t.getelement(r,c)
}
return temp;
}
```

```
Matrix & Matrix::operator=(const Matrix & q)
{
Matrix temp(3,3);
for (int r=0;r<3;r++)
for (int c=0;c<3;c++)
temp(r,c)=q.getelement(r,c);
return *this;
}
```

I believe one problem I have is too many parameters for operator+, but the only example my professor gave me had it with two parameters. I cut the implementation file down to the basic lines.

Thanks for whatever help possible.