(5/5)

Assume that a government wants to build a new road network to connect certain cities.

INSTRUCTIONS TO CANDIDATES

Assume that a government wants to build a new road network to connect certain cities. You are required to help the government by trying to minimize the cost of the new road network to be built by the government. Write the implementation of the GetMinCost function such that it takes as input an integer number N that represents the number of cities, and 2 double arrays that represent the latitude and longitude addresses of each city.

Assume that cities do not have obstacles between them, and you can build straight roads.

Assume that you can measure the distance in kilometers between two GPS points using ComputeDistance(lat1,long1, lat2, long2). The function returns the distance in km of a straight line between the two GPS points. The function is ready for you and can be used as is.

Assume that the cost of building a road between the two cities is the distance between them.

Output

Your function should calculate and print the minimum possible cost to build a road network that allows people to travel between any two of the given cities using the new road network.

Example 1:

N=5

latitudes 40.6943 34.1141 41.8375 25.784 32.7935

longitudes -73.9249 -118.4068 -87.6866 -80.2101 -96.7667

Output Expected 6207.15

Here's the code we need to edit: #include <iostream>

#include <math.h> #include <iomanip> #include <ios>

using namespace std;

#define M_PI 3.14159265358979323846

//do not change this function

{

double one_deg = (M_PI) / 180; return (one_deg * degree);

}

//do not change this function

double ComputeDistance(double lat1, double long1, double lat2, double long2)

{

double dlong = long2 - long1; double dlat = lat2 - lat1;

double ans = pow(sin(dlat / 2), 2) + cos(lat1) * cos(lat2) * pow(sin(dlong / 2), 2);

ans = 2 * asin(sqrt(ans)); double R = 6371;

ans = ans * R;

return ans;

}

// this is the function you need to implement

double GetMinCost (int N, double latitude[], double longitude[]){

}

Here's the main code:#include <iostream> using namespace std;

#include "Q1.cpp" int main(){

int N=5;

double latitudes[]={40.6943,34.1141,41.8375,25.784,32.7935};

double longitudes[]={-73.9249,-118.4068,-87.6866,-80.2101,-96.7667};

cout<<GetMinCost (N,latitudes,longitudes);

// result should be 6207.15 return 0;

}

(5/5)

Related Questions

. Introgramming & Unix Fall 2018, CRN 44882, Oakland University Homework Assignment 6 - Using Arrays and Functions in C

DescriptionIn this final assignment, the students will demonstrate their ability to apply two ma

. The standard path finding involves finding the (shortest) path from an origin to a destination, typically on a map. This is an

Path finding involves finding a path from A to B. Typically we want the path to have certain properties,such as being the shortest or to avoid going t

. Develop a program to emulate a purchase transaction at a retail store. This program will have two classes, a LineItem class and a Transaction class. The LineItem class will represent an individual

Develop a program to emulate a purchase transaction at a retail store. Thisprogram will have two classes, a LineItem class and a Transaction class. Th

. SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 1 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

. Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of Sea Ports. Here are the classes and their instance variables we wish to define:

1 Project 2 Introduction - the SeaPort Project series For this set of projects for the course, we wish to simulate some of the aspects of a number of

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

Hire Me

Hire Me

Hire Me
Atharva PatilComputer science

Hire Me

Get Free Quote!

321 Experts Online