/*
IsScalarMatrix
---------------
Check if a Matrix is a Scalar matrix
where: diagonal elements all contain the same scalar aij.
Return (!false == true,!true == false)
*/
bool CDblMatrix::IsS calarMatrix()
{
int nRows = 0, nCols = 0;
double temp;
if (m_nCols == m_nRows)
{
temp = m_ppData[0][0];
for (nRows = 0; nRows < m_nRows; nRows++)
{
for (nCols = 0; nCols < m_nCols; nCols++)
{
if ( nRows && nCols == 0)
{
if(((nRows != nCols) && (m_ppData[nRows][nCols])) != 0)
{
cout<< "The matrix is not a Scalar Matrix"<< endl;
return false;
}
else if (((nRows == nCols) && (m_ppData[nRows][nCols])) != temp)
{
cout<< "The matrix is not a Scalar Matrix"<< endl;
return false;
}
}
else
{
cout<< "The matrix is a Scalar Matrix"<< endl;
return true;
}
}
}
}
else
{
cout<< "The matrix is not a square matrix."<< endl;
return false;
}
}
Hi i am writing a code for the scalar matrix. But when i did the testing i got problem...as those are not scalar matrix but it was detected as scalar...so can u help me please...thank you
IsScalarMatrix
---------------
Check if a Matrix is a Scalar matrix
where: diagonal elements all contain the same scalar aij.
Return (!false == true,!true == false)
*/
bool CDblMatrix::IsS calarMatrix()
{
int nRows = 0, nCols = 0;
double temp;
if (m_nCols == m_nRows)
{
temp = m_ppData[0][0];
for (nRows = 0; nRows < m_nRows; nRows++)
{
for (nCols = 0; nCols < m_nCols; nCols++)
{
if ( nRows && nCols == 0)
{
if(((nRows != nCols) && (m_ppData[nRows][nCols])) != 0)
{
cout<< "The matrix is not a Scalar Matrix"<< endl;
return false;
}
else if (((nRows == nCols) && (m_ppData[nRows][nCols])) != temp)
{
cout<< "The matrix is not a Scalar Matrix"<< endl;
return false;
}
}
else
{
cout<< "The matrix is a Scalar Matrix"<< endl;
return true;
}
}
}
}
else
{
cout<< "The matrix is not a square matrix."<< endl;
return false;
}
}
Hi i am writing a code for the scalar matrix. But when i did the testing i got problem...as those are not scalar matrix but it was detected as scalar...so can u help me please...thank you
Comment