As you probably know, angle measurements geo coordinates are done in the form of
ID: 3677394 • Letter: A
Question
As you probably know, angle measurements geo coordinates are done in the form of degrees, minutes seconds, where there is 60 minutes in a degree and 60 seconds in a minute. Because it makes the math easier there is more and more a trend to show these assimply degrees with decimal Instead of 36 degrees and 45 minutes to show 36.7500 degrees). Your program that project is to write a allows the users to convert between the two. It will show a menu asking the user which way they want to convert The menu should be implemented using a do-while loop The conversions themselves should be done by two functions o Converting from degrees, minutes, seconds to decimal involves returning a single value, so this can be done with a function that takes three input parameters and returns the decimal degree (since that is a single number) o Converting from decimal degrees to degrees, minutes, seconds involves passing one input parameter and three "output parameters" the return statement of a function can only one thing. Look at the same program changes.c to see how I did this money Use the floor function from the math.h library to separate the whole number from fractional part of the decimal degrees Remember to compile with-lm when you use the math library Make use of casts (int) in front of a variable or expression makes it an integer, (double) in front of a variable or expression makes it a double Multiplying the fractional part of decimal degrees by 3600 will convert it into seconds, then you can use integer division and mod to separate minutes and seconds A sample output would look like this: m) To convert decimal degrees to degrees, inutes seconds d) To convert degrees, minutes, seconds to decinal degrees q) To quit Enter degrees as degrees minutes seconds with no decimals 36 45 2 36 degrees 45 minutes 2 seconds is 36 degrees in decimal format. Choose m) To convert decimal degrees to degree inutes, seconds. d) To convert degrees, minutes, seconds to decimal degrees. q) To quit Enter degrees in decimal format 36.7506 36.7506 degrees is 36 degrees, 45 minutes Choose m) To convert decimal degrees to degrees, inute seconds d) To convert degrees, minutes, seconds to decimal degrees Invalid choice. Please try again MORE ON THE BACKExplanation / Answer
#include<math.h>
#include<stdio.h>
void dms2deg(){
printf("Enter degrees as degrees minutes seconds with no decimals => ");
int degree, minute, second;
scanf("%d %d %d", °ree, &minute, &second);
float ans;
ans = degree + (minute/60.0) + (second/3600.0);
printf("%d degrees %d minutes %d seconds is %f in decimal format ",degree,minute,second,ans);
}
void deg2dms(){
float dd,temp;
printf("Enter degrees in decimal format => ");
scanf("%f",&dd);
temp = dd;
int d=0, m=0, s=0;
float minwork=0.0, secwork=0.0;
d = (int)dd;
dd = dd - d;
minwork = dd*60;
m = minwork;
dd = dd*100;
dd = dd - minwork;
dd = dd/100;
secwork = dd*60;
s = secwork;
printf("%f degrees in %d degrees, %d minutes, %d seconds ",temp,d,m,s);
}
void main(){
char option;
while(1){
printf("Choose m) To convert decimal degrees to degree, minutes, seconds d) To convert degree, minutes, seconds to decimal degrees q) To quit ");
scanf("%c",&option);
if (option == 'q')
break;
if (option =='d')
{dms2deg();
continue;
}
if (option =='m')
{deg2dms();
continue;}
printf("Invalid input ");
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.