Matrix

Hi i am trying to write a program that builds up matrices( without really using pointers) and i am using i stream and iostream. So when i ask my program to give me the elements of the first matrix, it works alright but when i give in the elements of the second matrix, the figures, i give in the figures but they come out different, in order from 0 to 9.. depending on howmany elements i have in my matrix. i dont really know where my mistake is. i cant find it. Can someone possibly help... please
write some code to better understand the problem
okay i ll implement the matrix.cpp, cuz its already so long i dont rreally know what to leave out


#include "myMatrix.h"

using namespace std;

unsigned MatrixBase::maxRow= 100;
unsigned MatrixBase::maxColumn= 100;
unsigned MatrixBase::counter= 0;

int Matrix<int>::_delta = (int) 0;
float Matrix<float>::_delta = (float) 0.001;
double Matrix<double>::_delta = (double) 0.001;

ostream& operator<< (ostream& o, Matrix<int>& m)
{
o<<"[ ";

for (unsigned i=1; i<=m._m;i++)
{
for (unsigned j= 1;j<=m._n;j++)
{
o<<m.getValue(i, j)<<" ";
if (j==m._n && (i*j !=m._m*m._n))
o<<endl<<" ";
}
}
o<<"]";
return o;
}

ostream& operator<< (ostream& o, Matrix<float>& m)
{
o<<"[ ";

for (unsigned i=1; i<=m._m;i++)
{
for (unsigned j= 1;j<=m._n;j++)
{
o<<m.getValue(i, j)<<" ";
if (j==m._n &&(i*j !=m._m*m._n))
o<<endl<<" ";
}
}
o<<"]";
return o;
}

ostream& operator<< (ostream& o, Matrix<double>& m)
{
o<<"[ ";
for (unsigned i=1; i<=m._m;i++)
{
for (unsigned j= 1;j<=m._n;j++)
{
o<<m.getValue(i, j)<<" ";
if (j==m._n &&(i*j !=m._m*m._n))
o<<endl<<" ";
}
}
o<<"]";
return o;
}

istream& operator>> (istream& i, Matrix<int>& m)
{
int value;
cout<<"[ ";

for (unsigned j=1; j<=m._m;j++)
{
for (unsigned k= 1;k<=m._n;k++)
{
i>>value;
m.setValue(j, k, value);
}
}
return i;
}

istream& operator>> (istream& i, Matrix<float>& m)
{
float value;
cout<<"[ ";

for (unsigned j=1; j<=m._m;j++)
{
for (unsigned k= 1;k<=m._n;k++)
{
i>>value;
m.setValue(j, k, value);
}
}
return i;
}

istream& operator>> (istream& i, Matrix<double>& m)
{
double value;
cout<<"[ ";

for (unsigned j=1; j<=m._m;j++)
{
for (unsigned k= 1;k<=m._n;k++)
{
i>>value;
m.setValue(j, k, value);
}
}
return i;

}
this is the cpp...
Please put your code between code syntax, and also provide your header and source file
Last edited on
Topic archived. No new replies allowed.