Run-Time Check Failure #2 - Stack around the variable 'box' was corrupted.

hey~im new to programming...i got the problem in my program.Can anyone help me to solve it?

Run-Time Check Failure #2 - Stack around the variable 'box' was corrupted.

here is my source code:

//function file//
#include"header.h"

//function to get data//
double matrix::getdata()
{
cout << "The calculation of matrices:" << endl;
/*get data for matrix 1*/
for(i = 1; i <= 3; i ++)
{
for(j = 1; j <=3; j ++)
{
cout << "Enter the data of matrix 1[" << i << "][" << j<< "]:";
cin >> a[i][j];
}
}

cout << "Matrix 1:" << endl;//display matrix 1
for(i = 1; i <= 3; i ++)
{
for(j = 1; j <=3; j ++)
cout << " " << a[i][j];
cout << endl;
}
cout << endl;

/*get data for matrix 2*/
for(i = 1; i <= 3; i ++)
{
for(j = 1; j <= 3; j ++)
{
cout << "Enter the data of matrix 2[" << i << "][" << j<< "]:";
cin >> b[i][j];
}
}

cout << "Matrix 2:" << endl;//display matrix 2
for(i = 1; i <= 3; i ++)
{
for(j = 1; j <= 3; j ++)
cout << " " << b[i][j];
cout << endl;
}
cout << endl;

return a[i][j], b[i][j];
}



//function to calculate the summation of matrices//
void matrix::sum()
{
cout << "Summation of matrix 1 and Matrix 2:" << endl;

for(i = 1; i <= 3; i ++)//calculate the summation
{
for(j = 1; j <= 3; j ++)
total[i][j] = a[i][j] + b[i][j];
}

for(i = 1; i <= 3; i ++)//display the total
{
for(j = 1; j <= 3; j ++)
cout << " " << total[i][j];
cout << endl;
}
}



//function to calculate the substraction of matrices//
void matrix::substraction()
{
cout << "Substraction of matrix 1 and matrix 2:" << endl;

for(i = 1; i <= 3; i ++)//calculate the substraction
{
for(j = 1; j <= 3; j ++)
subs[i][j] = a[i][j] - b[i][j];
}

for(i = 1; i <= 3; i ++)//display the total
{
for(j = 1; j <= 3; j ++)
cout << " "<< subs[i][j];
cout << endl;
}
}



//function to calculate the multiplication//
void matrix::multiplication()
{
cout << "Multiplication of matrix 1 and matrix 2:" << endl;

for(i = 1; i <= 3; i ++)//calculate the multiplication
{
for(j =1; j <= 3; j ++)
{
mul[i][j] = 0;
for(k = 1; k <= 3; k ++)
{
mul[i][j] += a[i][k] * b[k][j];
}
}
}

for(i = 1; i <= 3; i ++)//display the total
{
for(j = 1; j <= 3; j ++)
cout << " " << mul[i][j];
cout << endl;
}
cout << endl;
}



//function to transpose the matrices//
double matrix::transpose()
{
cout << "Transpose of matrix 1:" << endl;//transpose of matrix 1
for(i = 1; i <= 3; i ++)
{
for(j = 1; j <= 3; j ++)
trana[j][i] = a[i][j];
}

for(i = 1; i <= 3; i ++)//display the transpose of matrix 1
{
for(j = 1; j <= 3; j ++)
cout << " " << trana[i][j];
cout << endl;
}
cout << endl;


cout << "Transpose of matrix 2:" << endl;//transpose of matrix 2
for(i = 1; i <= 3; i ++)
{
for(j = 1; j <= 3; j ++)
tranb[j][i] = b[i][j];
}

for(i = 1; i <= 3; i ++)//display the transpose of matrix 2
{
for(j = 1; j <= 3; j ++)
cout << " " << tranb[i][j];
cout << endl;
}
cout << endl;

return trana[i][j], tranb[i][j];
}



//function of symmetric checking of matrix 1//
void matrix::sysmmetric1()
{
for(i = 1; i <= 3; i ++)
{
for(j = 1; j <= 3; j ++)
{
if(trana[i][j] == a[i][j])
continue;
else
{
cout << "Matrix 1 is not symmetric." << endl;
}
}
}
cout << "Matrix 1 is symmetric." << endl;
}



//function of symmetric checking of matrix 2//
void matrix::sysmmetric2()
{
for(i = 1; i <= 3; i ++)
{
for(j = 1; j <= 3; j ++)
{
if(tranb[i][j] == b[i][j])
continue;
else
{
cout << "Matrix 2 is not symmetric." << endl;
}
}
}
cout << "Matrix 2 is symmetric." << endl;
}

//main file//
#include"header.h"

int main()
{
matrix box;//object
box.getdata();//calling function"getdata"
box.sum();//calling function"sum"
box.substraction();//calling function"substraction"
box.multiplication();//calling function"multiplication"
box.transpose();//calling function"transpose"
box.sysmmetric1();//calling function"sysmmetric1"
box.sysmmetric2();//calling function"sysmmetric2"

system("pause");
return 0;

}
[code] "Please use code tags" [/code]
array index goes from 0 to n-1

Making a matrix class that actually holds two matrices is confusing.
Last edited on
Topic archived. No new replies allowed.