#include <memory.h>
#define FLOAT float
#define UINT unsigned int
class CMatrix
{
UINT _i,_j;
FLOAT *_data;
public:
CMatrix();
virtual ~CMatrix();
void Initialize(UINT i,UINT j,FLOAT *data);
FLOAT getMin();
FLOAT getMax();
FLOAT getDiffSumm(FLOAT min,FLOAT max) const;
FLOAT getSumm() const;
};
CMatrix::CMatrix():_i(0),_j(0),_data(0)
{
}
CMatrix::~CMatrix()
{
delete[]_data;
}
void CMatrix::Initialize(UINT i,UINT j,FLOAT *data)
{
_i=i,_j=j;
if(_data)
delete[]_data;
_data=new FLOAT[_j*_i];
memcpy(_data,data,sizeof(FLOAT)*_i*_j);
}
FLOAT CMatrix::getMin()
{
FLOAT min=_data[0];
UINT i;
for(i=1;i<_i*_j-1;i++)
if(min<_data[i])
min=_data[i];
return min;
}
FLOAT CMatrix::getMax()
{
FLOAT max=_data[0];
UINT i;
for(i=1;i<_i*_j-1;i++)
if(max<_data[i])
max=_data[i];
return max;
}
FLOAT CMatrix::getSumm() const
{
FLOAT summ=0;
UINT i;
for(i=0;i<_i*_j;i++)
summ=summ+_data[i];
return summ;
}
FLOAT CMatrix::getDiffSumm(FLOAT min,FLOAT max)const
{
FLOAT ret=getSumm();
FLOAT summ=0;
UINT i;
for(i=0;i<_i*_j;i++)
{
if(_data[i]<min)
{
summ=summ+min;
}
else
if(_data[i]>max)
{
summ=summ+max;
}
else summ=summ+_data[i];
}
return (ret-summ);
}
int main(void)
{
FLOAT data[9]={0,1,2,3,4,5,6,7,8};
CMatrix matr;
matr.Initialize (3,3,data);
FLOAT diff=matr.getDiffSumm (2,7);
return 0;
}