1. Engineering
  2. Computer Science
  3. c program for matrices write a matrix class which represents...

Question: c program for matrices write a matrix class which represents...

Question details

C++ Program for Matrices.

Write a Matrix class, which represents an m x n matrix of integers. (Matrix.h and Matrix.cc). Your class should include the following member functions:

Note: For all classes, use const member functions when appropriate. Also write a Makefile which can be used to compile all programs.

·Constructor: accepts m and n as parameters and constructs a matrix of the requested size. Initializes all entries to 0. Use the default values m 2. void getDimensions (int &m, int &n); returns the dimensions of the matrix. . element: takes the indices i and j and returns a reference to the element. Also write a version that returns a constant (for constant Matrices). Use assert to ensure that the indices are within valid range. . add, subtract: takes one additional Matrix parameter and replace the current object by the sum/difference of itself and the supplied parameter. Use assert to ensure that the dimensions of the two matrices are compatible. » multiply: takes one additional Matrix parameter B and computes the product of the matrix with B. The result is returned as a new Matrix object. Use assert to ensure that the dimensions of the two matrices are compatible. Recall: if A is a p × q matrix and B is a q × r matrix, their product C is a p × r matrix where each element of C is given by i.j . read, write: reads a matrix (dimensions and elements in row-major order) from cin, writes the matrix to cout

2. Using the Matrix class above, write a program (calc.cc) that (a) Reads in three matrices A, B, and C (b) Sets D to be the same matrix as A except that entries in the first column are 0. c)Computes and displays the following results: What happens when the matrices have incompatible dimensions for the operations above? Type your answer into the file ans.txt.

Remark: the program will likely have memory leaks. Do not worry about this.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution