A Cartesian coordinate system is an orthogonal coordinate system. Points can lie in two or three dimensional space (x,y,z). If we start with a two-dimensional system, the first thing to do is to randomly generate 100 points P(x,y).
The points can have positive or negative x and y values. The task sets the range to positive numbers between 1 and 100. The data type can be defined by the user.
I would suggest here integers, which should be generated by a random generator. So you call the random generator 100 times and get suitable values for x and y. If you use a standard C++ container, you can collect and sort the coordinates. To specify the nearest points in the distribution for each point you have to calculate the distance to all other points for each point and remember the shortest distance and point to be able to output the point.
You could start like this:
#define MAX_POINTS 100
#define MAX_RANGE 100
typedef struct{
int x, y;
} KOORD;
int myrandom(int min, int max)
{
int n=0;
return n;
}
int main()
{
vector <KOORD> p;
for (int i = 0; i < MAX_POINTS; i++) {
KOORD newpoint;
newpoint.x = ...
I have deliberately kept the ball flat here. Furthermore, I deliberately do not present a complete program here, because otherwise hardly any learning effect would come out.
If an more advanced C++ solution is desired, Palini's suggestion would be appropriate.
Note: The output with the nearest points is not formulated clearly enough and can be interpreted differently. While Palini outputs the two points that are closest together, one could also output the closest to each point. Or it is meant still differently.