Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

INTRODUCTION: Points on the Earths surface can be computed by two angles, the polar angle a, and the azimuth angle b. The polar angle is

INTRODUCTION:

Points on the Earths surface can be computed by two angles, the polar angle a, and the azimuth angle b. The polar angle is a reference direction from a known axis (the z axis) through the center of the Earth. The azimuth angle is the angle between the projected vector and a reference vector (the x axis) on a reference plane (the x-y plane). See the illustration below.

and can be computed, in terms of latitude and longitude, by the following expressions:

If the first city has a North latitude, 1 = 90 - latitude, else 1 = 90 + latitude.

If the second city has a North latitude, 2 = 90 - latitude, else 2 = 90 + latitude.

If the first city has a West longitude, 1 = longitude, else 1 = 360 - longitude.

If the second city has a West longitude, 2 = longitude, else 2 = 360 - longitude.

Hint: When computing and , latitude and longitude must be converted from degrees and minutes to decimal degrees. There are 60 minutes in one degree of latitude or longitude. Thus, if a coordinate is 25 degrees 30 minutes the decimal degrees would be 25.5 degrees.

Once two points on the Earth are known, like the location of two cities, the angle of separation between the two locations can be determined by the equation:

separation_angle = acos(cos(a1) * cos(a2) + sin(a1) * sin(a2) * cos(b2 - b1))

Finally, the distance between two cities can be determined by:

distance = separation_angle * earth_radius

In the preprocessor directive section, define pi and Earth radius as symbolic variables. To obtain the most accurate computations, for pi use 3.141592654 and for the Earth radius use 3958.89 (this is miles).

The input file called cities contains: 1) the number of cities; 2) the names of the cities, and their respective latitude (degrees and minutes) and longitude (degrees and minutes) coordinates. The coordinates are relative to the North Pole and the prime meridian which passes through Greenwich, England. Note that latitude increases as a city's position is located further south from the North Pole, and that longitude increases as a city's position is located further west from the prime meridian.

EXAM:

Using an array of structures, write a C program that will compute the surface distance between a pair of cities. Use a for loop to read all the data from the input file into the array of structures. Use another for loop to control the computations and printing operations. The cites must be paired as follows: Montreal and London, Chicago and Melbourne, and so on. In your defined structure, the members must be: 1) a character array for the city name: 2) character variables for hemisphere and direction; 3) variables for the latitude and longitude values. Your program will print to the computer screen and to an output file called surface_distance.

NOTE: All variable names must be meaningful variables. Except for pi and loop control variables, do not use single letter or double letter or single letter and number variables. It is required that you use the appropriate built-in C math functions in your equations.

OUTPUT FORMAT:

**********************************************

SURFACE DISTANCE CALCULATIONS

CITY LATITUDE LONGITUDE

Deg Min Deg Min

sssssssssssssss xxx xx.x c xxx xx.x c

sssssssssssssss xxx xx.x c xxx xx.x c

Distance between the two cities = xxxx.x miles

sssssssssssssss xxx xx.x c xxx xx.x c

sssssssssssssss xxx xx.x c xxx xx.x c

Distance between the two cities = xxxx.x miles

sssssssssssssss xxx xx.x c xxx xx.x c

sssssssssssssss xxx xx.x c xxx xx.x c

Distance between the two cities = xxxx.x miles

sssssssssssssss xxx xx.x c xxx xx.x c

sssssssssssssss xxx xx.x c xxx xx.x c

sssssssssssssss xxx xx.x c xxx xx.x c

sssssssssssssss xxx xx.x c xxx xx.x c

Distance between the two cities = xxxx.x miles

**********************************************

here is what I have so far

/* Preprocessor directives */ #include #include #define pi 3.141592654 #define erad 3958.89 #define inputfile "C:\Users\Brenden\Documents\Brenden School\engr 200\Exam 3\ cities.txt" #define outputfile "C:\Users\Brenden\Documents\Brenden School\engr 200\Exam 3\ surface_distance.txt"

/* Define the structure of the program */

struct cities { char city[15], direclat[2], direclon[2]; double latdeg, latmin, londeg, lonmin };

/* Main function */ int main(void) { /* Declare Variables */ struct cities globe[10], temporary; double distance, polar, azimuth, latdecdeg, londecdeg; int i, j, ndata; FILE *coord, *surface; /* Open input and output files */ coord = fopen("cities.txt","r"); surface = fopen("surface_distance.txt", "w"); /* Verify input file and read input data */ if(coord == NULL) { printf(" Error opening input file occured "); printf(" Program terminated "); return 0; }

/* Read Control Number */ fscanf(coord, "%i", &ndata);

/* read structured array data */ for(i=0; i<=ndata-1; i++) { fscanf(coord, "%s %lf %lf %s %lf %lf %s", &globe[i].city, &globe[i].latdeg, &globe[i].latmin, &globe[i].direclat, &globe[i].londeg, &globe[i].lonmin, &globe[i].direclon); } /* compute decimal degrees */ /* computer polar and azimuth angle */

/* sort tsunamis by wave height */ /* compute min and max wave height */ /* Print Main Headings */ printf("**********************************************"); printf(" SURFACE DISTANCE CALCULATIONS " " CITY LATITUDE LONGITUDE " " Deg Min Deg Min "); fprintf(surface, "**********************************************"); fprintf(surface, " SURFACE DISTANCE CALCULATIONS " " CITY LATITUDE LONGITUDE " " Deg Min Deg Min "); /* print structured array data */ for(i=0; i<=ndata-1; i++) { fscanf(coord, "%s %lf %lf %s %lf %lf %s", &globe[i].city, &globe[i].latdeg, &globe[i].latmin, &globe[i].direclat, &globe[i].londeg, &globe[i].lonmin, &globe[i].direclon); printf(" %-15s %3.0f %4.1f %s %3.0f %4.1f %s", &globe[i].city, &globe[i].latdeg, &globe[i].latmin, &globe[i].direclat, &globe[i].londeg, &globe[i].lonmin, &globe[i].direclon); fprintf(surface," %-15s %3.0f %4.1f %s %3.0f %4.1f %s", &globe[i].city, &globe[i].latdeg, &globe[i].latmin, &globe[i].direclat, &globe[i].londeg, &globe[i].lonmin, &globe[i].direclon);

} printf(" Distance between the two cities = %6.1f miles", distance); /*print output footer */ printf(" ********************************************** "); fprintf(surface, " ********************************************** " " "); /* close input and output file */ fclose(coord); fclose(surface); /*Exit the Program*/ return 0; }

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

Professional Microsoft SQL Server 2014 Integration Services

Authors: Brian Knight, Devin Knight

1st Edition

1118850904, 9781118850909

More Books

Students also viewed these Databases questions