Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Matrix.h file -------------------------------------------------------------------------------------- ------ #include #include #include using namespace std; class Matrix { private: vector > M; unsigned int ROWS; unsigned int COLS; bool operationIsValid(const

Matrix.h file -------------------------------------------------------------------------------------- ------ #include #include #include using namespace std; class Matrix { private: vector > M; unsigned int ROWS; unsigned int COLS; bool operationIsValid(const Matrix &, const string&) const; public: //Constructors Matrix(); Matrix(const string&); Matrix(int,int,int); //Accessors const Matrix transpose() const; const Matrix add(const Matrix &m) const; const Matrix subtract(const Matrix &m) const; const Matrix multiply(const Matrix &m) const; const void saveMatrix(const string&) const; //Friend function friend ostream & operator 

Main.cpp file -----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include "Matrix.h" #include #include #include //declare operator> operationChoice; if(operationChoice == 1 || operationChoice == 2 || operationChoice == 3) { cout > matFile1; cout > matFile2; Matrix A(matFile1); Matrix B(matFile2); if(operationChoice == 1) res = A.add(B); if(operationChoice == 2) res = A.subtract(B); if(operationChoice == 3) res = A.multiply(B); } else if(operationChoice == 4) { cout > matFile1; Matrix A(matFile1); res = A.transpose(); } cout > displayChoice; if(displayChoice == 1){ cout > resFile; res.saveMatrix(resFile); } else if(displayChoice == 2){ cout  

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

For example: if A = B.transpose(), then a[i][j] = b[j][i]. 

-const Matrix add(const Matrix &m) const: adds the corresponding elements of the two matrices and returns result.

For example: if C = A.add(B), then c[i][j] = a[i][j] + b[i][j]. 

-const Matrix subtract(const Matrix &m) const: subtracts the elements of the two matrices and returns result.

For example: if C = A.subtract(B), then c[i][j] = a[i][j] - b[i][j]. 

-const Matrix multiply(const Matrix &m) const: multiplies the elements of the two matrices and returns result.

For example: (A and B are 2 X 2 matrices) if C = A.multiply(B) and , then c[0][0] = a[0][0] * b[0][0] + a[0][1] * b[1][0]. 

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Implement member functions of a Matrix class in a file named "Matrix.cpp" that stores elements of a matrix and is capable of performing basic operations.

----------------------------------------------------------------------------------------------------------------------------------------------------------------

image text in transcribed

Global Function -friend ostream & operator

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

Building Database Driven Catalogs

Authors: Sherif Danish

1st Edition

0070153078, 978-0070153073

More Books

Students also viewed these Databases questions

Question

Identify the cause of a performance problem. page 363

Answered: 1 week ago