Define a Class for Matrix Manipulation (2)

  1. Modify the "matrix.h" file in your previous exercise about class CMatrix so that,
  2. private data members become:
    1. unsigned short m_Row;
    2. unsigned short m_Column;
    3. int entry[3 * 3];
  3. Modify member functions accordingly:
    1. Constructor: Assign the value 3 to m_Row and m_Column, and calls Set(i,j,n) to assign a value to an entry.
    2. Get(i,j): returns the value of entry[i * m_Column + j], where 0<=i<=2, 0<=j<=2.
    3. Set(i,j,n): assigns value n to entry[i * m_Column + j].
    4. Print(): calls Get(i,j) to print out the entries.
    5. 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