Quote:
struct matrixType{
int matDimension;
int matValues[10][10];
};
What is the purpose of the
matDimension
member, since you have hard-wired dimensions (namely
10x10
)?
As first attempt, you could implement your
Matrix
class, this way:
#include <iostream>
#include <iomanip>
using namespace std;
class Matrix
{
static const int N = 10;
int m[N][N];
public:
Matrix();
Matrix & add(const Matrix & other);
void show();
};
Matrix::Matrix()
{
for (int i=0; i<N; ++i)
for (int j=0; j<N; ++j)
m[i][j] = 0;
}
Matrix & Matrix::add(const Matrix & other)
{
for (int i=0; i<N; ++i)
for (int j=0; j<N; ++j)
m[i][j] += other.m[i][j];
return *this;
}
void Matrix::show()
{
for (int i=0; i<N; ++i)
{
for (int j=0; j<N; ++j)
cout << m[i][j] << " ";
cout << endl;
}
}
int main()
{
Matrix m;
m.show();
}