d radius X arccos sinx1 X sinx2 cosx1 X cosx2 X cosy1 y2

d = radius X arccos( sin(x1) X sin(x2) + cos(x1) X cos(x2) X cos(y1 – y2) ) Write a program that prompts the user to enter the GPS coordinates of two locations in degrees and display the great circle distance between the two locations. Must use c++ (must be completed with selections, mathematical functions, characters and strings that is the level we are at and cant go beyond that)

Here is a sample run: Enter location 1 (latitude and longitude) in degrees: 39.55, -116.25 [enter] Enter location 2 (latitude and longitude) in degrees: 41.5, 87.37 [enter] The distance between the two locations is 10691.79183231593 km

Solution

// C++ code determine the great circle distance between the two locations

#include <iostream>
#include <string.h>
#include <fstream>
#include <limits.h>
#include <stdlib.h>
#include <math.h>
using namespace std;

int main ()
{
const double PI = 3.14159265358979;

double x1,y1;
double x2, y2;

double radius = 6371;

cout << \"Enter point 1 (latitude and longitude) in degrees: \";
cin >> x1 >> y1;

cout << \"Enter point 2 (latitude and longitude) in degrees: \";
cin >> x2 >> y2;

x1 = (x1*PI)/180;
y1 = (y1*PI)/180;
x2 = (x2*PI)/180;
y2 = (y2*PI)/180;

double distance = radius*acos(sin(x1)*sin(x2)+ cos(x1)*cos(x2)*cos(y1-y2));
cout << \"The distance between he two points is \" << distance << \" km \" << endl;

return 0;
}


/*
output:

Enter point 1 (latitude and longitude) in degrees: 39.55 -116.25
Enter point 2 (latitude and longitude) in degrees: 41.5 87.37

The distance between he two points is 10691.8 km

*/

d = radius X arccos( sin(x1) X sin(x2) + cos(x1) X cos(x2) X cos(y1 – y2) ) Write a program that prompts the user to enter the GPS coordinates of two locations

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site