Reference no: EM132196844
Question :
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 where Aij is the matrix entry at the intersection of the i-th row and j-th column with rows numbered from top to bottom (and similarly for the matrices B and C).
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).
Create two instances A and B of class Matrix in the main method, set their elements by using the file redirection, and demonstrate the usage of the class methods by computing the sum and the product of two input matrices and displaying the resulting ones with the class method printMatrix().