The program should receive the input coordinates from the command line on the model (x; y), it seems like all the rules, but gives an error. I would be grateful if they told me what causes it in my program and how to remove it.
PS And in general, the task is looking for a pair of nearest points on opposite sides of OY
#include <stdio.h> #include <math.h> class Point2 { private: int y; int x; public: Point2(int _x, int _y) : x(_x), y(_y) { }; int get_x() { return x; }; int get_y() { return y; }; friend double distance(Point2* r, Point2* q); }; double distance(Point2* r, Point2* q) { int dis = (r->get_x() - q->get_x())*(r->get_x() - q->get_x()) + (r->get_y() - q->get_y())*(r->get_y() - q->get_y()); return (sqrt(dis)); } int main(int argc,char* argv[]) { double sum,min; Point2** p; Point2* t; Point2* f; int x, y; int i = 0; int j = 0; if (argc < 2) return (-1); p = new Point2*[argc]; printf("%d \n",argc); while (++i < argc) { sscanf( argv[i] ,"(%d%*c%d)", &x, &y ); p[j] = new Point2(x, y); printf ("%d ..... %d \n", x, y); j++; } for (i = 0; p[i] != NULL; i++) { min = 0; t = p[i]; f = NULL; if (t->get_x() != 0) for (j = 0; p[j] != NULL; j++) if ( ( (p[j]->get_x())*(p[i]->get_x()) ) < 0 ) { sum = distance(p[i], p[j]); if ((min == 0) || (sum < min)) { min = sum; f = p[j]; t = p[i]; } } } if (min>0) printf("Point1(%d,%d) Point2(%d,%d) min dist = %f\n", t->get_x(), t->get_y(), f->get_x(), f->get_y(), min); else printf("Net podhodyachih to4ek"); for (j = 0; p[j] != NULL; j++) delete p[j]; delete[] p; return 0; }
1
:) - HolyBlackCat February