npoint.c

来自「聚类算法Enclus的源程序」· C语言 代码 · 共 65 行

C
65
字号
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "NPoint.h"

// Constructor
NPoint::NPoint()
{
  dim = 50;

  coord = new float[dim];
  if (coord==NULL) {
    printf("Warning: Memory allocation error\n");
  }
}

NPoint::NPoint(int d)
:dim(d)
{
  coord = new float[dim];
  if (coord==NULL) {
    printf("Warning: Memory allocation error\n");
  }
}

// Copy constructor
NPoint::NPoint(const NPoint& p)
{
  dim = p.dim;
  
  coord = new float[dim];
  memcpy(coord, p.coord, dim*sizeof(float));
}
   
// Destructor
NPoint::~NPoint()
{
  delete[] coord;
}

// Show the point
void NPoint::show()
{
  int j;
  
  for (j=0; j<dim; j++) {
    printf("%f ",coord[j]);
  }
}

void NPoint::show(FILE* fp)
{
  int j;
  
  for (j=0; j<dim; j++) {
    fprintf(fp,"%f ",coord[j]);
  }
}

// Set the value of a dimension
void NPoint::set_value(int d, float v)
{
  coord[d] = v;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?