Pointer 와 Dynamic Storage 를 이용해야합니다.. 도와주세요~
별
밑에있는 프로그램은 제가 클래스를 이용해서 3x3행렬 덧셈,뺄쌤,곱셈 , 행렬식을 구했는데요.
요번에는 포인터와 Dynamic Storage만 이용해서 3x3행렬 덧셈,뺄쌤,곱셈 , 행렬식을 구해야합니다...
제가 포인터대해서 잘 몰라서그러는데요... 근데 확실한건 밑에있는 프로그램에서 몇가지만 바꾸기만 하면 된다는건 알아요
private: 에서float *a[3][3] 이런식으로별표를 붙여야 하는건 대충알겠는데..
님들아 도와두세요
//////////////////////
#includeiostream
using namespace std;
class matrices
{
public:
void myreadin();
void addmatrices();
void submatrices();
void multimatrices();
void determatrices();
void printout();
private:
float a[3][3];
float b[3][3];
float c[3][3];
float d[3][3];
float e[3][3];
float det;
};
int main()
{
matrices m1;
printf(Please enter the first 3x3 matrix first, then underneath the second 3x3 \n);
m1.myreadin();
m1.addmatrices();
m1.submatrices();
m1.multimatrices();
m1.determatrices();
m1.printout();
return 0;
}
void matrices::myreadin()
{
int i,j;
for (int i=0; i3; i++)
for(int j=0; j3; j++)
scanf(%f ,&a[i][j]);
for (int i=0; i3; i++)
for(int j=0; j3; j++)
scanf(%f ,&b[i][j]);
}
void matrices::addmatrices()
{
int i,j;
for (int i=0; i3; i++)
{
for (int j=0; j3; j++)
{
c[i][j]=a[i][j]+b[i][j];
}
}
}
void matrices::submatrices()
{
int i,j;
for (int i=0; i3; i++)
{
for (int j=0; j3; j++)
{
d[i][j]=a[i][j]-b[i][j];
}
}
}
void matrices::multimatrices()
{
int q,w,i;
for(int q=0; q3; q++)
{
for(int w=0; w3; w++)
{
e[q][w]=0;
for(int i=0; i3; i++)
{
e[q][w] += a[q][i] * b[i][w];
}
}
}
}
void matrices::determatrices()
{
{
det = a[0][0] * (a[2][2] * a[1][1]- a[2][1] * a[1][2]) - a[1][0]* (a[2][2] * a[0][1] - a[2][1] * a[0][2]) + a[2][0] *( a[1][2] * a[0][1\
] - a[1][1] * a[0][2]);
}
}
void matrices::printout()
{
printf(The first input matrix\n);
for (int i=0; i3; i++)
{
for(int j=0; j3; j++)
printf(%f ,a[i][j]);
coutendl;
}
printf(The second input matrix\n);
for (int i=0; i3; i++)
{
for(int j=0; j3; j++)
printf(%f ,b[i][j]);
coutendl;
}
printf(The sum of two matrices is\n);
for (int i=0; i3; i++)
{
for(int j=0; j3; j++)
printf(%f ,c[i][j]);
coutendl;
}
printf(The difference of two matrices is\n);
for (int i=0; i3; i++)
{
for(int j=0; j3; j++)
printf(%f ,d[i][j]);
coutendl;
}
printf(The product of two matrices is\n);
for (int i=0; i3; i++)
{
for(int j=0; j3; j++)
printf(%f ,e[i][j]);
coutendl;
}
coutThe determinant of two matrices is: detendl;
}