Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

To create a program that accomplishes the ... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Systems Analysis And Design

Authors: Alan Dennis, Barbara Wixom, Roberta M. Roth

7th Edition

1119496489, 978-1119496489

More Books

Students also viewed these Programming questions