1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99
|
//
// CPS 216
// 4/5/2014
// this program takes latitude and longitude in degreees
// and turns it into radians using a function
#include <iostream> // for input putput
#include <string> //
#include <cmath> // for calculation of conversrion
using namespace std;
// variables****************************************************************
const double pi= 3.1415;
double coord1(0),coord2(0),coord3(0),coord4(0);
double rad1,rad2,rad3,rad4;
double dist, direction,direction2,direction3,direction4;
// function to convert coordinates******************************************
double radiancoord(double coord,double direc)
{
double n(1),N(1),E(1),e(1);
double rad;
if (direc=1)
{
rad = ((coord*pi)/180);
return rad;
}
else
{
rad = -((coord*pi)/180);
return rad;
}
}
// distance function ************************************************************
double CoordDistance(double lat1,double lon1,double lat2, double lon2)
{
double distance;
distance = sqrt(pow((lat2-lat1),2)+pow((lon2-lon1),2))*3956.57;
return distance;
}
// begining of main code ****************************************************
int main()
{
// program definition********************************************************
cout << "This program turns longitude and latitude in degrees" << endl;
cout << " into radians and also tells the distance between 2 points" << endl;
cout << "Positive is North/East negitive is South/West \n" << endl;
// get users first coordinate************************************************
cout << "longitude/latitude" << endl;
cout << "Enter the first locations coordinates: " ;
//enter longitude for first point
cin >> coord1;
cin >> direction;
// enter latitude for first point
cin >> coord2;
cin >> direction2;
// put information into functions
rad1=radiancoord(coord1,direction);
rad2=radiancoord(coord2,direction2);
// output information from first point
cout << "The location in radians is: " << rad1 <<", "<< rad2 << endl;
cout << "\n";
// get users second coordinate************************************************
cout << "longitude/latitude" << endl;
cout << "Enter the second locations coordinates: " ;
// enter latitude
cin >> coord3;
cin >> direction3;
// enter the longitude
cin >> coord4;
cin >> direction4;
// put information into function
rad3=radiancoord(coord3,direction3);
rad4=radiancoord(coord4,direction4);
// output coordinate
cout << "The coordinates in radians are: " << rad3 <<", "<< rad4 << endl;
cout << "\n";
// find the distance between points************************************
dist=CoordDistance(rad1,rad2,rad3,rad4);
cout << "the distance between the points is"<< endl;
cout << dist << " miles" << endl;
return 0;
}
|