1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
class point2d{
public:
//point2d(){ };// default constructor
point2d(float x, float y); // constructor
~point2d(); // destructor
float distance(point2d p);
float mX,mY; // member variables
};
point2d::point2d(float x, float y) {
mX=x;
mY=y;
}
point2d::~point2d(void){
// nothing in here, yet
}
float point2d::distance(point2d p){
float dist=0;
float x=0, y=0;
x=(mX-p.mX);
y=(mY-p.mY);
dist=sqrt((x*x)+(y*y));
return dist;
}
class ShortestPath
{
public:
ShortestPath(vector<point2d> point_values);//, vector<int>& ord, int n, int c, int ck); // constructor
~ShortestPath(void); // destructor
protected:
vector<point2d> points; // <-------are you sure this is causing the problem?
};
ShortestPath::ShortestPath(vector<point2d> point_values)//, vector<int>& ord, int n, int c, int ck)
{
points = point_values;
// order = ord;
// NumberOfPoints = n;
// choose_k = ck; // this is the user chosen k-nearest neighbours
// choose = c;
}
ShortestPath::~ShortestPath(void){}
int main(void)
{
//vector<point2d> pts;
//pts.push_back( point2d(1.0f, 1.1f) );// use of your constructor is OK here.
//pts.push_back( point2d(2.0f, 1.2f) );
//pts.push_back( point2d(3.0f, 1.3f) );
//ShortestPath path(pts);
int NumberOfPoints = 10;
vector<point2d> arraypoints(NumberOfPoints);
vector<int> order(NumberOfPoints);
for (int i = 0; i < NumberOfPoints; i++){ // this loop calculates 2 sets of random numbers (x,y) and sets order to be 0,1,2,3....
arraypoints[i].mX = 10 * rand() / float(RAND_MAX);
arraypoints[i].mY = 10 * rand() / float(RAND_MAX);
order[i] = i;
cout << order[i] << " " << arraypoints[i].mX << " " << arraypoints[i].mY << endl;
}
cout << endl << endl;
system("PAUSE"); // yes i know i shouldn't use this, but just for convenience at the minute
return 0;
}
|