Hi Madosenshi,
there is nothing pathetic about asking for help, its why this forum is here after all (:
The first question is, are you familiar with matrices ? obviously if you haven't covered that this task will not make any sense, if you have covered matrices, most of what is being asked for here should be fairly easy:
To start with the constructor:
all it needs to do is populate the internal array of integers from the values passed in:
1 2 3 4 5 6 7
|
Matrix::Matrix(int a, int b, int c, int d)
{
m[0][0] =a;
m[0][1] =b;
m[1][0] =c;
m[1][1] =d;
}
|
these:
1 2 3 4
|
Matrix operator+(const Matrix& a);
Matrix operator-(const Matrix& a);
Matrix operator*(const Matrix& a);
void operator=(const Matrix& a);
|
are operator overloads; if someone uses your library to define two matrices and wishes to add them together, you as a programmer, need to explain to the compiler what an "add" between two "Matrices" is:
1 2 3
|
Matrix matrix_a(1, 2, 3, 4);
Matrix matrix_b(4, 3, 2, 1);
Matrix matrix_c = matrix_a+matrix_b;
|
in this situation the overloaded + operator within matrix_a would receive a constant referance to matrix_b.
thus inside the +operator definition you need to write some code to add all of the elements within the array "m" of the two matrices together, use those values to create a new matrix and then return it, so it can be used:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
Matrix Matrix::operator+(const Matrix &a)
{
int val_0_0 =m[0][0];
int val_0_1 =m[0][1];
int val_0_2 =m[1][0];
int val_0_3 =m[1][1];
int val_1_0 =a.m[0][0];
int val_1_1 =a.m[0][1];
int val_1_2 =a.m[1][0];
int val_1_3 =a.m[1][1];
Matrix return_matrix(val_0_0+val_1_0,
val_0_1+val_1_1,
val_0_2+val_1_2,
val_0_3+val_1_3 )
}
|
the remaining functions should be very similar, and a 3v3 matrix class is at least 90% identical to this one.
I hope this helps
Thanks - NGangst