Question: C++ format For this program you will be given a list of city names and x, y coordinates that signify the location of the city.
C++ format
For this program you will be given a list of city names and x, y coordinates that signify the location of the city. You will store the list of cities in an array of structures and then use that array to write a series of functions.The data will be in a text file named "route_data.txt" and will be in the following format:
city x_coord y_coord
e.g.
Houston 0.5 1.6 Denver -1.5 4.2
etc.
The cities are in order. The first city is your home city. You will figure out how far it is from your home city to the last city in the list by moving from city to city in the list and calculating the total distance (we are assuming that we have cars that fly through the air and can use a straight line distance). Then you will write a function to improve the ability to visit each city once (the last city you visit may change).
You will write four functions for this program:
//reads the initial data from the input file //returns false if the file is not opened correctly bool getData(string inputFile, City cities[], int &numCities);
//prints the cities in order, one per line void printRoute(City cities[], int numCities);
//calculates the distance from one city to the next double getDistance(City city1, City city2);
//calculates the total distance from the first city to the last city double totalDistance(City cities[], int numCities);
//uses an algorithm to make the total distance shorter than the initial distance (if possible) void improveRoute(City cities[], int numCities);
Your main program should have the following algorithm:
get the data
print the route
show the total distance
improve the route
print the route
show the total distance
display the percentage improvement
We will discuss the details of the assignment in class, including a simple route improving algorithm (although you may come up with something better on your own)
The input file is named "route_data.txt" consisting of the following coordinates:
San_Marcos 0.0 0.0 Omaha 1.5 6.3 Austin 0.5 1.2 Chicago 3.1 8.2 Dallas 0.8 3.4 Denver -1.5 7.4 Houston 1.8 -0.7 McGregor 1.2 10.6
C++ format
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
