C++ class to model the mathematical operations of a matrix. Your class should in
ID: 643299 • Letter: C
Question
C++ class to model the mathematical operations of a matrix. Your class should include the following functions.
add() which adds two matrices
power() which raises the first matrix to power n
== which returns true if both matrices are equal. You need to overload the C++ equality operator.
should be in three files mat.cpp testmat.cpp & mat.h
out put run follows.
Enter the number of rows: 2
Enter the number of columns: 3
Enter the elements of matrix 1 row by row:
1 0 3
5 1 2
Enter the elements of matrix 2 row by row:
1 1 2
1 0 4
matrix 1 == matrix 2?
No
matrix 1 + matrix 2:
2 1 5
6 1 6
matrix 1 power n. Enter n: 2
1 0 9
25 1 4
Explanation / Answer
#include "mat.cpp"
#include <iostream>
using namespace std;
int main(){
int rows, cols;
cout << "Enter the number of rows: ";
cin >> rows;
cout << "Enter the number of columns: ";
cin >> cols;
cout << "Enter the elements of matrix 1 row by row:" << endl;
matrix A(rows, cols);
cout << "Enter the elements of matrix 2 row by row:" << endl;
matrix B(rows, cols);
cout << "matrix 1 == matrix 2?" << endl;
if(A == B){
cout << "Yes" << endl;
}
else{
cout << "No" << endl;
}
cout << "matrix 1 + matrix 2:" << endl;
A.add(B).print();
cout << "matrix 1 power n. Enter n: ";
int n;
cin >> n;
A.power(n).print();
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.