#ifndef CLASS_DEFINITION_H
#define CLASS_DEFINITION_H
#include <iostream.h>
#include <windows.h>
#include <stdio.h>
#include <conio.h>
#include <math.h>
#define MATRIX_SIZE_X 2
#define MATRIX_SIZE_Y 2
class matrix { // класс матриц
private:
float *mData;
int mSizeY;
int mSizeX;
int refCount;
public:
matrix (int sx,int sy)
{
int i=0;
mSizeY = sy;
mSizeX = sx;
refCount = 0;
mData = new float[sx*sy];
while(i<(sx*sy)){mData[i++]=0;};
};
~matrix() {if((refCount--)<1){delete[] mData;}}
float operator[](int i){return mData;}
matrix operator=(matrix &b);
matrix operator+(matrix &b);
matrix operator-(matrix &b);
matrix operator*(matrix &b);
matrix operator*(float f);
void Determinant();
void Trans();
void Matrix_obratnaya();
matrix Power(matrix a,int n);
void In_put();
void Out_put();
};
matrix matrix::operator = (matrix &b)
{
int i=0; refCount++;
while(i<(mSizeX*mSizeY)){mData=b;i++;}
return *this;
};
matrix matrix::operator * (matrix &b)
{
int i=0; refCount++;
while(i<(mSizeX*mSizeY)){mData[i++]*=b;i++;}
return *this;
};
matrix matrix::operator * (float f)
{
int i=0; refCount++;
while(i<(mSizeX*mSizeY)){mData[i++]*=f;}
return *this;
};
matrix matrix::operator + (matrix &b)
{
int i=0; refCount++;
while(i<(mSizeX*mSizeY)){mData+=b;i++;}
return *this;
};
matrix matrix::operator - (matrix &b)
{
int i=0; refCount++;
while(i<(mSizeX*mSizeY)){mData-=b;i++;}
return *this;
};
void matrix::Determinant()
{
cout<<"detM="<<mData[0]*mData[3]- mData[1]*mData[2]<<endl;
};
void matrix::Trans()
{
for(int i=0;i<mSizeX;i++)
{
for(int j=0;j<mSizeY;j++)
{printf("[%d,%d]=%f ",i,j,mData[(j*mSizeX)+i]);}
cout<<endl;
}
cout<<endl;
};
void matrix::Matrix_obratnaya()
{
float d;
d=1/(mData[0]*mData[3]- mData[1]*mData[2]);
float *tmp = new float[mSizeX*mSizeY];
for(int i=0;i<mSizeX;i++){
for(int j=0;j<mSizeY;j++) {
tmp[0]=d*mData[3];
tmp[1]=(-1)*d*mData[1];
tmp[2]=(-1)*d*mData[2];
tmp[3]=d*mData[0];
printf("[%d,%d]=%f",i,j,tmp[(i*mSizeY)+j]);}
cout<<endl;}
cout<<endl;
};
matrix matrix::Power(matrix a,int n)
{
cin>>n;
if (n==1) return a;
else return a*Power(a,n-1);
}
void matrix::Out_put()
{
for(int i=0;i<mSizeX;i++)
{
for(int j=0;j<mSizeY;j++)
{printf("[%d,%d]=%f ",i,j,mData[(i*mSizeY)+j]);}
cout<<endl;
}
cout<<endl;
};
void matrix::In_put()
{
for(int i=0;i<mSizeX;i++)
{
for(int j=0;j<mSizeY;j++){cin>>(mData[(i*mSizeX)+j]);}
}
};
#endif
Работа с матрицами
Помогите, пожалуйста.
Вот код ( если будет интересно , то скину и весь проект ) :
Код: