📄 gene.cc
字号:
// gene.cc// Implementation of class Gene// Thomas Pederson, 950505#include "gene.h"#include <string.h>#include <math.h>Gene::Gene(char *_name, coord_t _x, coord_t _y, unsigned int _index, unsigned int _distVecLength){ name = new char[nameLength]; strncpy(name, _name, nameLength); distVecLength = _distVecLength; distance = new distance_t[distVecLength]; for (int i = 0; i < distVecLength; i++) distance[i] = -1.0; x = _x; y = _y; index = _index;}Gene::~Gene(){ cout << "destructing [" << index << "]: " << name << endl; delete [] name; delete [] distance;}// Calculates Eucledian distance between this gene and// _gene and returns the value.distance_t Gene::calculateDistanceTo(Gene& _gene){ distance[_gene.getIndex()] = sqrt(pow((x - _gene.x), 2) + pow((y - _gene.y), 2)); }// Returns Eucledian distance between this gene and _gene.distance_t Gene::distanceTo(Gene& _gene){ return distance[_gene.getIndex()];}// Prints gene information to stream.ostream& operator<<(ostream& outStr, Gene& gene){ cout << "[" << gene.index << "]: " << gene.name << " (" << gene.x << "," << gene.y << ")"; return outStr;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -