Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Your goal is to print the cities in United States sorted in the increasing order of distance from Charlotte. Download from Canvas the text file

Your goal is to print the cities in United States sorted in the increasing order of distance from Charlotte. Download from Canvas the text file (cities.txtimage text in transcribed) containing the latitude and longitude information of nearly 30,000 cities in the United States. Calculate the distance from Charlotte to each of these cities. Sort the cities in ascending order of distance, and print the sorted list along with the distance from Charlotte, to an output file dist_clt.txt. Sample entries in your output would look like this Yorktown,IA 867.294 Here, 867.294 is the distance in miles from Charlotte. Do a sanity check to make sure your output is correct! Use the Haversine formula to calculate the great-circle distance between two points that is, the shortest distance over the earths surface giving an as-the-crow-flies distance between the points (ignoring any hills they fly over, of course!). Haversine formula: delta_phi = phi(city) - phi(Charlotte) delta_lambda = lambda(city) - lambda(Charlotte) a = sin(delta_phi/2) + cos(phi1)*cos(phi2)*sin(delta_lambda/2) c = 2*atan2(sqrt(a), sqrt(1-a)) d = R*c where phi is latitude, lambda is longitude, R is earths radius (mean radius = 3,959 miles); Note that angles need to be in radians to pass to trig functions! The latitude and longitude of Charlotte is 35.2060,-80.8290 Hint: Carefully think of the operations that you need to do - read line from file; split line into city name & state, latitude, longitude; store these in a data structure; calculate the distance; sort by distance to Charlotte; and print the output.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

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

Harness The Power Of Big Data The IBM Big Data Platform

Authors: Paul Zikopoulos, David Corrigan James Giles Thomas Deutsch Krishnan Parasuraman Dirk DeRoos Paul Zikopoulos

1st Edition

ISBN: 0071808183, 9780071808187

More Books

Students also viewed these Databases questions

Question

Discuss the techniques of sales forecasting.

Answered: 1 week ago

Question

Write short notes on Marketing mix.

Answered: 1 week ago