Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program Description Write a program that calculates the distance between two places on Earth, based on their latitude and longitude. Prompt the user to enter

Program Description

Write a program that calculates the distance between two places on Earth, based on their latitude and longitude. Prompt the user to enter the latitude and longitude of two places. The Earths mean radius is to be taken as 6371.01 km. Use user-defined variables with descriptive names wherever necessary. Following steps will have to be followed:

  1. Program must have header comments stating the author of the Program, date, and Program Description.
  2. Include the math.h header file
  3. Initialize a variable with the value of earths radius. (Take earths radius as i).
  4. Prompt the user to enter the Starting Latitude. Read that number into a user-defined variable. (Remember to convert the input to float. Also the input needs to be further converted to radians.) You may use value of PI as 3.141592654
  5. Step 4 has to be repeated for accepting the values of Starting Longitude, Ending Latitude, and Ending Longitude.
  6. Compute the distance between the two places using any one of the following formulas:

Spherical Law of Cosines:

distance =

R*acos(sin(start_lat)*sin(end_lat)+cos(start_lat)*cos(end_lat)*cos(start_long- end_long))

where R = Earths Radius

Haversine Formula:

R = earths radius difflat = end_lat start_lat difflong = end_long start_long a = sin(difflat/2) + cos(start_lat) * cos(end_lat) * sin(diflong/2) c = 2 * atan2(sqrt(a), sqrt(1-a)) d = R * c

  1. Display the distance between the two places as:

The distance between the two places is (calculated distance) kms.

----------------------------------------------------------------------------------------------------------------------------------

in the above is a question about C program that calculates the distance between two places on Earth, i did this cod can any one check it for me and help me with Conversion of degrees to radians and also how i can add an Extra loop Construct for Making the program execute continuously, till user asks to exit! OR Maybe the way constants are declared in the preprocessor phase of the program execution!

this is my coding

#include #include #include #include #include name date and discrption of the program

int main() { const float Redues=6371.01; float start_lat, start_long, end_lat, end_long, Distance; printf("Input Start Latitude: "); scanf("%f", &start_lat); printf("Input Start Longitude: "); scanf("%f", &start_long); printf("Input End Latitude: "); scanf("%f", &end_lat); printf("Input End Longitude: "); scanf("%f", &end_long); Distance =(R*acos(sin(start_lat)*sin(end_lat)+cos(start_lat)*cos(end_lat)*cos(start_long- end_long))); printf("Distance between the said points: %.2f", sqrt(Distance)); printf(" km"); printf(" "); return 0; }

----------------------------------------------------------------------

what else do i have to add??

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

Advances In Databases And Information Systems 23rd European Conference Adbis 2019 Bled Slovenia September 8 11 2019 Proceedings Lncs 11695

Authors: Tatjana Welzer ,Johann Eder ,Vili Podgorelec ,Aida Kamisalic Latific

1st Edition

3030287297, 978-3030287290

More Books

Students also viewed these Databases questions