#include #include #include #include #define sqr(a) ((a)*(a)) using namespace std; const int dim=2; class POINT { public: POINT(double *crds); void getCoords(double *crds) const; void setCoords(const double *crds); private: double coords[dim]; }; POINT::POINT(double *crds) { assert(crds != NULL); memcpy(coords, crds, dim*sizeof(double)); } void POINT::getCoords(double *crds) const { assert(crds != NULL); memcpy(crds, coords, dim*sizeof(double)); } void POINT::setCoords(const double *crds) { memcpy(coords, crds, dim*sizeof(double)); assert(crds != NULL); } class BOND { public: BOND(POINT *ip1, POINT *ip2); void getPoints(POINT *&op1, POINT *&op2); private: POINT *p1; POINT *p2; }; BOND::BOND(POINT *ip1, POINT *ip2) { p1 = ip1; p2 = ip2; } void BOND::getPoints(POINT *&op1, POINT *&op2) { op1 = p1; op2 = p2; return; } //-------------------------------------- // double separation(const double* p1, const double* p2) { double distsq = 0.0f; for(int i=0; i < dim; ++i) distsq += sqr(p1[i] - p2[i]); return sqrt(distsq); } double separation(const POINT& p1, const POINT& p2) { double coords1[dim], coords2[dim]; p1.getCoords(coords1); p2.getCoords(coords2); return separation(coords1, coords2); } double separation(BOND &b1) { POINT *p1, *p2; b1.getPoints(p1,p2); return separation(*p1,*p2); } //-------------------------------------- // int main() { double coords1[] = {0.0f, 0.0f}; double coords2[] = {3.0f, 4.0f}; POINT p1(coords1); POINT p2(coords2); BOND b(&p1,&p2); cout <<"dist = "<