Im lost, parallel arrays

I am beyond lost with this extra credit assignment for class. I dont even know where to start so any help would be appreciated. the directions are:

1. We want to generate some points on the computer screen. The position of each point consists of an x coordinate, which records the horizontal position of the point, and a y coordinate, which records the vertical position of the point. The distance dis(p1, p2) between two points P1(x1, y1) and P2(x2, y2) is calculated in this way: dis(p1, p2) = sqrt((x1-x2)*(x1-x2) + (y1-y2)*(y1-y2)).

Task 1: Please declare two parallel arrays to hold the positions for 6 points (one array holds the x coordinates for the points and another array holds the y coordinates for the points). Use one loop to get the coordinates of the 6 points from a user.


Task 2: Calculate the distance between each pair of points and store the distances in a 2 dimensional array (it is called a distance matrix). For example, dis[0][1] stores the distance between point 0 and point 1. Print the distance array on screen row by row.

Task3: Using the distance matrix to find the nearest neighbor of each point. For example, the nearest neighbor of point 2 is the point with the smallest distance to point 2 among point 0, point 1, point 3, point 4, and point 5. Print the results in this way:

0 Index of point 0’s nearest neighbor (is it point 1, 2, 3, 4 or 5 and print its distance)

1 Index of point 1’s nearest neighbor (is it point 0, 2, 3, 4 or 5 and print its distance)



5 Index of point 5’s nearest neighbor (is it point 0, 1, 2, 3, or 4 and print its distance)
Please show your code - don't forget to use code tags - the <> button on the right.

If your code doesn't compile - then post the full compiler output.
THats the problem, I dont have any code yet. I dont know where to start. I may be making it harder then it should be but i as of right now i am beyond confused. Thanks for your reply
with this extra credit assignment for class


You must have some idea - surely if you are after extra credit?

Do you know about arrays & functions, loops?

Can you design your code by writing comments that specify each step to be carried out? This can be an iterative process - start off with very general ideas of the process, then go back & add more steps until you are comfortable with writing code. Leave the comments in - they serve as documentation.

The thing is we will not write the code for you - just give out hints & ideas instead. You have to show that you have done some thinking / put in some effort yourself - then you will get some help.

What specifically are you confused about?
I know loops and arrays, i am just not sure what all task 2 and 3 are asking
Topic archived. No new replies allowed.