Problem Statement Consider two locations, an origin and a destination, on the globe identified by their latitude and longitude. The distance between these two locations can be computed using the Spherical Law of Cosines. In particular, the distance d is d = arccos (sin(2) sin(2) + cos(P1)cas(2) cos(A)) - R where • pa is the latitude of location A, 22 is the latit ude of location B • Ais the difference between location B's langitude and location A's longitude Ris the (average) radius of the earth, 6,371 kilometers Write a program that prompts the user to enter the latitude and longitude of two locations and then computes the distance between them using the above formula. Note that latitude inputs will be in degrees and in the range [-90, 90] and longitude will be in degrees in the range [-180, 180 . Negative values correspond to the westem and southem hemispheres. Hack 2.0 - Computer Science I 1/2

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
**Problem Statement**

Consider two locations, an origin and a destination, on the globe identified by their latitude and longitude. The distance between these two locations can be computed using the Spherical Law of Cosines. In particular, the distance \( d \) is 

\[ d = \arccos(\sin(\varphi_1) \sin(\varphi_2) + \cos(\varphi_1) \cos(\varphi_2) \cos(\Delta)) \cdot R \]

where 

- \( \varphi_1 \) is the latitude of location A, \( \varphi_2 \) is the latitude of location B
- \( \Delta \) is the difference between location B’s longitude and location A’s longitude
- \( R \) is the (average) radius of the earth, 6,371 kilometers

Write a program that prompts the user to enter the latitude and longitude of two locations and then computes the distance between them using the above formula. Note that latitude inputs will be in degrees and in the range \([-90, 90]\) and longitude will be in degrees in the range \([-180, 180]\). Negative values correspond to the western and southern hemispheres.

---

*Hack 2.0 – Computer Science I*                                                                      *1 / 2*
Transcribed Image Text:**Problem Statement** Consider two locations, an origin and a destination, on the globe identified by their latitude and longitude. The distance between these two locations can be computed using the Spherical Law of Cosines. In particular, the distance \( d \) is \[ d = \arccos(\sin(\varphi_1) \sin(\varphi_2) + \cos(\varphi_1) \cos(\varphi_2) \cos(\Delta)) \cdot R \] where - \( \varphi_1 \) is the latitude of location A, \( \varphi_2 \) is the latitude of location B - \( \Delta \) is the difference between location B’s longitude and location A’s longitude - \( R \) is the (average) radius of the earth, 6,371 kilometers Write a program that prompts the user to enter the latitude and longitude of two locations and then computes the distance between them using the above formula. Note that latitude inputs will be in degrees and in the range \([-90, 90]\) and longitude will be in degrees in the range \([-180, 180]\). Negative values correspond to the western and southern hemispheres. --- *Hack 2.0 – Computer Science I*                                                                      *1 / 2*
The page provides instructions for calculating air distance based on latitude and longitude, which need to be measured in radians. To convert degrees to radians, use the formula:

\[
r = \frac{deg}{180} \cdot \pi
\]

**Output Example**

Your output should look like this:

```
Location Distance
==================
Origin: (41.948300, -87.655600)
Destination: (40.820600, -96.705600)
Air distance is 764.990931 kms
```

**Instructions**

- **Collaboration**: Collaborate with any number of students during your hack session.
  
- **Design Test Cases**: Create at least 3 test cases before programming to ensure correctness.
  
- **Include Names**: Add the names of collaborators in the source file's header.
  
- **Program Naming**: Name your program `airDistance.c` and submit via webhandin, ensuring correct execution. Each student submits their own copy for individual grading.
  
- **RTM (Read The Manual)**: Consult the math library manual to understand useful functions.
  
- **Compiler/System Configuration**: You might need to use the `-lm` flag to link the math library:

  ```bash
  gcc -lm airDistance.c
  ```

  Or on certain systems (e.g., ubuntu/CS50):

  ```bash
  gcc airDistance.c -lm
  ```
Transcribed Image Text:The page provides instructions for calculating air distance based on latitude and longitude, which need to be measured in radians. To convert degrees to radians, use the formula: \[ r = \frac{deg}{180} \cdot \pi \] **Output Example** Your output should look like this: ``` Location Distance ================== Origin: (41.948300, -87.655600) Destination: (40.820600, -96.705600) Air distance is 764.990931 kms ``` **Instructions** - **Collaboration**: Collaborate with any number of students during your hack session. - **Design Test Cases**: Create at least 3 test cases before programming to ensure correctness. - **Include Names**: Add the names of collaborators in the source file's header. - **Program Naming**: Name your program `airDistance.c` and submit via webhandin, ensuring correct execution. Each student submits their own copy for individual grading. - **RTM (Read The Manual)**: Consult the math library manual to understand useful functions. - **Compiler/System Configuration**: You might need to use the `-lm` flag to link the math library: ```bash gcc -lm airDistance.c ``` Or on certain systems (e.g., ubuntu/CS50): ```bash gcc airDistance.c -lm ```
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps with 2 images

Blurred answer
Knowledge Booster
Fundamentals of Boolean Algebra and Digital Logics
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education