Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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.

image text in transcribed

image text in transcribed

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

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

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions

Question

What is your organizations mind-set about complaints?

Answered: 1 week ago