Design the following member functions:
- A constructor CMatrix(int n = 0), which will dynamically
allocate an integer array with n*n entries, let m_Row = m_Column = n,
and initialize all entries to become 0.
- Another constructor CMatrix(int m, int n, int v = 0), which
will dynamically allocate an integer array with m*n entries, let
m_Row = m, m_Column = n, and initialize all entries to be v.
- A copy constructor CMatrix(CMatrix& B) which will allocate an
integer array with the same size as matrix B, and duplicate the
corresponding entries in matrix B.
- A destructor to release the integer array allocated for this
object, and print out a message like "Destructor called for a m*n
matrix", where m is the value of m_Row, and n is the value of
m_Column.
- Print() - print out the matrix with m_Row rows and m_Column
columns. Note that integers in a column should be right-justified.
- MaxEntry() - returns the maximum of absolute value among all
entries. This is helpful to determine the maximum width required in
printing entries when you want to keep them right-justfied.
- Because m_Row and m_Column are private data members, you need
to design public member functions Row() and Column() to return the
value of m_Row and m_Column, respectively.
- Get(i, j): returns the value of the (i*m_Column+j)th entry of
the dynamically allocated array.
- Set(i, j, n): assigns n to the (i*m_Column+j)th entry of
the dynamically allocated array.
Test your class definition with this main
program.
Save your class definition in "matrix.h" and compile the program with
"clang++ matrix-4.cpp".
The running result should look like:
Constructor called for a 3*4 matrix.
Copy Constructor called for a 3*4 matrix.
1 1 1 1
1 1 1 1
1 1 1 1
88 1 1 1
1 1 1 1
1 1 1 1
Destructor called for a 3*4 matrix.
Destructor called for a 3*4 matrix.