Really i need help to complete my program but i don't know how to fix the errors ..
the program is about 2 Dimensional Arrays matrix operations
i wrote the whole program but there is some mistakes plz i need help to finish it im too confused !!
#include <iostream>
using namespace std;
template < typename T >
class Matrix
{
private:
T M[100][100];
int rowsize;
int colsize;
public:
void set_par(T x, int rp, int cp)
{
M[rp][cp]=x;
}
Matrix ( int r , int c )
{
rowsize = r;
colsize = c;
}
void add ( T x , int rp , int cp )
{
M[rp][cp] += x;
}
T retrieve ( int rp , int cp )
{
return M[rp][cp];
}
int getrow ()
{
return rowsize ;
}
int getcoluomn ()
{
return colsize ;
}
void display()
{
for ( int i=0 ; i<rowsize ; i++)
{
for ( int j=0 ; j<colsize ; j++)
{ cout<< M[i][j];
}
cout<<endl;
}
}
};
template < typename T >
void m_add ( Matrix<T> &z, Matrix<T> x , Matrix<T> y , int r , int c )
{
if(x.getrow()==y.getrow() && x.getcoluomn()==y.getcoluomn())
{
for ( int i=0 ; i<r ; i++)
for ( int j=0 ; j<c ; j++)
z.set_par(x.retrieve(i,j) + y.retrieve(i,j),i,j) ;
}
}
template < typename T >
void m_sub ( Matrix <T> &z, Matrix <T> x , Matrix <T> y , int r , int c )
{
if(x.getrow()==y.getrow() && x.getcoluomn()==y.getcoluomn())
{
for ( int i=0 ; i<r ; i++)
for ( int j=0 ; j<c ; j++)
z.set_par(x.retrieve(i,j) - y.retrieve(i,j),i,j) ;
}
}
template < typename T >
void m_mult ( Matrix <T> &z, Matrix <T> x , Matrix <T> y , int r , int c , int q)
{
if(x.getrow()==y.getrow() && x.getcoluomn()==y.getcoluomn())
{
for (int i=0; i<r; i++)
{
z.set_par(0,0,0);
for (int j=0; j<c; j++)
{
for (int k=0; k<q; k++)
{
z.set_par(z.retrieve+(x.retrieve(i,k) * y.retrieve(k,j)),i,j)
z[i][j] += x[i][k] * y[k][j];
}
cout << z[i][j] << " ";
}
cout<<endl;
}
}
}
template < typename T >
void m_trans( Matrix <T> x , Matrix <T> y , int r , int c )
{
if(x.getrow()==y.getrow() && x.getcoluomn()==y.getcoluomn())
{
for (int i=0; i<r; i++)
for (int j=0; j<c; j++)
y[j][i]=x[i][j];
}
}
int main ()
{
int x;
Matrix <int> A (3,3);
Matrix <int> B (3,3);
Matrix <int> C (3,3);
Matrix <int> temp (3,3);
cout<<"Enter matrix A:"<<endl;
for ( int i=0 ; i<3 ; i++)
for ( int j=0 ; j<3 ; j++)
{
cin>>x;
A.set_par(x,i,j);
}
cout<<"Enter matrix B:"<<endl;
for ( i=0 ; i<3 ; i++)
for ( int j=0 ; j<3 ; j++)
{
cin>> x;
B.set_par(x,i,j);
}
cout<<"Enter matrix C:"<<endl;
for ( i=0 ; i<3 ; i++)
for ( int j=0 ; j<3 ; j++)
{
cin>> x;
C.set_par(x,i,j);
}
m_add(temp,A,B,3,3);
temp.display();
m_add(temp,B,C,3,3);
temp.display();
m_sub(temp,B,A,3,3);
temp.display();
m_mult(temp,A,C,3,3,3);
temp.display();
m_mult(temp,C,A,3,3,3);
temp.display();
m_trans(temp,B,3,3);
temp.display();
m_trans(temp,C,3,3);
temp.display();
return 0;
}