Question: Your program takes in two integers from the interactive user: K and N. K is the number of cities to be visited. N is the

Your program takes in two integers from the interactive user: K and N. K is the number of cities to be visited. N is the length of one side of a square grid within which the K cities will be located. Your program should make sure that the user enters an integer K such that 4 <= K <= 9, and an integer N such that 10 <= N <= 30. Your program then randomly selects integer coordinates for each of the K cities, so that each city lies within a Cartesian coordinate system that goes from 0 to N on both the x and y axes. (NOTE: be careful that you include the possibility of 0 as a coordinate for both x and y.) Using text, show the user where the cities appear on the grid. (One method would be to use periods for empty grid cells and the digits 0 to ( K-1) to show where each city resides. Be careful about spacing, though.) Next, calculate the distance from each city to all the other cities, and print out a matrix that includes each of those distances. (The distances should be real numbers, displayed to at least one decimal place on the screen. Your program should store and use better precision than the one decimal place shown on the screen.) Next, using a brute force technique, determine the shortest route through the cities. Always start with the first city, city 0. As your program checks paths, always print out to the screen when you find the shortest route so far. Include in your printout to the screen cities the path goes through (in order) and its (shortest so far) length. Make sure the interactive user can see what’s going on by marking the output appropriately. Remember that for relatively large K there may be MANY “smallest so far” routes before finishing all the routes. Your last “smallest so far” solution will be the overall shortest path.

Step by Step Solution

3.40 Rating (153 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

To create a program that accomplishes the ... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!