Define a Class for Matrix Manipulation (2)
- Modify the "matrix.h" file in your previous exercise about
class CMatrix so that,
- private data members become:
- unsigned short m_Row;
- unsigned short m_Column;
- int entry[3 * 3];
- Modify member functions accordingly:
- Constructor: Assign the value 3 to m_Row and m_Column,
and calls Set(i,j,n) to assign a value to an entry.
- Get(i,j): returns the value of entry[i * m_Column + j], where
0<=i<=2,
0<=j<=2.
- Set(i,j,n): assigns value n to entry[i * m_Column + j].
- Print(): calls Get(i,j) to print out the entries.
- Add(CMatrix B): add each entry of this object
and the corresponding entries of matrix B, save them in a temporary matrix, and
return that matrix which stores the result of addition.
This is why the statement
c = a.Add(b); can store the addition result in matrix c.
Test your class definition with this main
program.
Save your class definition in "matrix.h" and compile the program with
"clang++ matrix-2.cpp".
The running result should look like:
3 3 3
3 12 3
3 3 101