Using C (NOT C++) create a \"printRoute\" function to traverse a linked list. Th
ID: 3761892 • Letter: U
Question
Using C (NOT C++) create a "printRoute" function to traverse a linked list. The function should have
1) 1 pass-by-reference parameter, a linked list
The function should print each location on the list and the distance between it and the next location*, the last location should print the distance between it and the first location, then finally, print the total trip distance. function should return void.
*Finding distance based on Latitude and Longitude using Haversine formula
double HaverseineDistance(double inStartLatitude, double inStartLongitude, double inEndLatitude, double inEndLongitude)
{
const double pi = 3.14159265358979323846
const double earthRadiusMiles = 3961.0
double startLatitudeRadians = (inStartLatitude * pi / 180.0)
double startLongitudeRadians = (inStartLongitude * pi / 180.0)
double endLatitudeRadians = (inEndLatitude * pi / 180.0)
double endLongitudeRadians = (inEndLongitude * pi / 180.0)
double subResult1 = sin((endLatitudeRadians startLatitudeRadians)/2)
double subResult2 = sin((endLongitudeRadians startLongitudeRadians)/2)
return 2.0 * earthRadiusMiles * asin(sqrt(subResult1 * subResult1 + cos(startLatitudeRadians) * cos(endLatitudeRadians) * subResult2 * subResult2))
}
Explanation / Answer
Program code for Finding distance based on Latitude and Longitude using Haversine formula :
// haverseine distance.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include<iostream>
using namespace std;
double HaverseineDistance(double inStartLatitude, double inStartLongitude, double inEndLatitude, double inEndLongitude)
{
const double PI = 3.1415926535897931;
const double earthRadiusMiles = 3961.0;
double startLatitudeRadians=(inStartLatitude * PI / 180.0);
double startLongitudeRadians =( inStartLongitude * PI / 180.0);
double endLatitudeRadians = (inEndLatitude * PI / 180.0);
double endLongitudeRadians = (inEndLongitude * PI / 180.0);
double subResult1 =sin((endLatitudeRadians-startLatitudeRadians)/2.0);
double subResult2 = sin((endLongitudeRadians-startLongitudeRadians)/2.0);
double final1=pow(subResult1,2)+cos(endLatitudeRadians)*cos(startLatitudeRadians)*pow(subResult2,2);
return 2.0 * earthRadiusMiles * atan2(sqrt(final1),sqrt(1-final1));//modified formula
}
int main()
{
printf("Distance=");
printf("%e ",HaverseineDistance(12.3,15.4,67.8,98.4));
system("pause");
return 0;
}
Sample output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.