the question is using oop implement a matrix class that provides the basic matrix operations (addition, subtraction, multiplication, Inverse, Transportation).
do i need to create a class or write the program codes
To create a class you write the program's code.
Anyway, using oop means that you have to create a class. That class should contain a matrix (meaning an array of arrays) of elements on which you will perform the calculations needed by matrix operations.
this is the solution, pls someone should help me with the correction, the question is using oop implement a matrix class that provides the basic matrix operations (addition, subtraction, multiplication, Inverse, Transportation).
#include <iostream>
using namespace std;
int main;
class matrix
{
int **p, m, n;
public:
matrix(int row = 2, int col = 2)
{
m = row;
n = col;
p = new(int *); m;
for (int i = 0; i < m; i++)
p[i] = new int[n];
}
~matrix()
{
for (int i = 0; i < m; i++)
delete p[i];
delete p;
}
void accept()
{
cout<<"Enter matrix elements:";
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
cin >> p[i][j];
}
}
}
void display()
{
cout <<"The matrix is:";
for(int i = 0; i < m; i++)
{
cout <<endl;
for(int j = 0; j < n; j++)
{
cout << p[i][j] <<" ";
}
}
}
matrix operator +(matrix m2)
{
matrix T(m, n);
for(int i = 0; i < m; i++)
{
for(int j = 0; j < n; j++)
{
T.p[i][j] = p[i][j] + m2.p[i][j];
}
}
return T;
}
friend matrix operator * (matrix, matrix);
};
matrix operator * (matrix a , matrix b)
{
if(a.n == b.m)
{
matrix T(a.m, b.n);
for(int i = 0; i < a.m; i++)
{
for(int k = 0; k < b.n; k++)
{
T.p[i][k] = 0;
for(int j = 0; j < a.n; j++)
{
T.p[i][k]+= a.p[i][j] * b.p[j][k];
}
}
}
return T;
}
}
Here is a revision of the previous, still has some bugs. I have to use friend operators instead of matrix operators to avoid overwritting valueable data. This can be easily. I will check back here tomorrrow
So you sent me a private msg last Friday asking me to do this assignment for you. I foolishly wrote the code on Saturday, but as you haven't replied to any of my messages, I haven't handed the code over. Good luck...
please im so sorry ajh32, i didnt receive any of your message, thank you @ eklavya sharma 2, scam89, and ajh32, i really appreciate your contributions, i will do it know, thanks once again