Apr 26, 2014 at 6:34am Apr 26, 2014 at 6:34am UTC
How do you know you're getting an infinite loop? When is the application stopping?
Apr 26, 2014 at 6:57am Apr 26, 2014 at 6:57am UTC
Run it...application not stopping
Apr 26, 2014 at 8:54am Apr 26, 2014 at 8:54am UTC
Could you enlighten us with some more information? Where exactly does the program not stop?
Also, <iostream.h> is depreciated; use <iostream> instead. void main() is not even legal C++. It must always be int main(). I strongly suggest you update your compiler if it's letting this compile, as it means your compiler is not even compliant with standards set over a decade ago.
Apr 26, 2014 at 8:55am Apr 26, 2014 at 8:55am UTC
Member variables 'r' and 'c' are not initialized for matrix "m3" in "add", "sub"
and "tps" funtions.
Corrected funtions
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
matrix matrix::add(matrix m2)
{
matrix m3;
m3.r=r;
m3.c=c;
for (int i=0;i<m2.getr();i++)
for (int j=0;j<m2.getc();j++)
{
m3.m[i][j]=m[i][j]+m2.m[i][j];
}
return (m3);
}
matrix matrix::sub(matrix m2)
{
matrix m3;
m3.r=r;
m3.c=c;
for (int i=0;i<m2.getr();i++)
for (int j=0;j<m2.getc();j++)
{
m3.m[i][j]=m[i][j]-m2.m[i][j];
}
return (m3);
}
matrix matrix::tps()
{
matrix m3;
m3.r=c;
m3.c=r;
for (int i=0;i<c;i++)
for (int j=0;j<r;j++)
m3.m[i][j]=m[j][i];
return m3;
}
To avoid this type of problems, always initialize the member variables in the constructor to suitable values.
Last edited on Apr 26, 2014 at 8:57am Apr 26, 2014 at 8:57am UTC