Write a C++ program that uses class Matrix for dealing with the square matrices (n x n tables of integers). The class constructor has to create a dynamic nxn matrix for n passed as a parameter. Supply the class with a copy constructor. Two overloaded operators + and * have to be implemented for adding and multiplying two matrices, respectively. The sum and product of two matrices A and B are square matrices with the entries defined as follows:
Cij = Aij + Bij, i=1,...,n, j=1,...,n
Cij = Ai1*B1j + Ai2*B2j + ... + Ain*Bnj
The matrix elements have to be initialized by the method setMatrix() that reads the matrix elements from the standard input from a file by using the redirection of input. The file have to contain 2·n2 matrix elements (for two nxn matrices) separated by spaces corresponding to the row-by-row scan of each matrix. The program must figure out the matrix dimension n automatically (n must not be a part of input).
This solution provides a C++ program that uses a class matrix for dealing with the square matrices.