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
|
#include "stdafx.h"
#include "stdio.h"
#include "string.h"
#include "math.h"
#define MAX 4
#define PI 3.14159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200
double getDistance(double lat1, double long1, double lat2, double long2);
double deg2rad(double deg);
struct Airport {
char Code[MAX];
double Lat, Long, Speed;
}Port, Port2;
struct Leg {
double Distance, Time;
};
int main()
{
int Legs;
printf("Welcome aboard! \n\nThis program will show you an awesome graph of your trip's\n legs' Speed, Disatance, and the travel time\n");
printf("\nHow many legs are there?\n");
scanf("%d", &Legs);
Airport *ports = new Airport[Legs +1];
for (int i = 0; i < Legs + 1; i++) {
printf("Please enter airport %d three letter code >", i+1);
scanf("%s", ports[i].Code);
printf("Please enter the latitide for airport %s >", ports[i].Code);
scanf("%lf", &ports[i].Lat);
printf("Please enter the longitude for airport %s >", ports[i].Code);
scanf("%lf", &ports[i].Long);
printf("Please enter the ground speed you are travelling from airport %s >", ports[i].Code);
scanf("%lf", &ports[i].Speed);
}
Leg *flight = new Leg[Legs];
for (int i = 0; i < Legs; i++) {
flight[i].Distance = getDistance(ports[i].Lat, ports[i].Long, ports[i + 1].Lat, ports[i + 1].Long);
flight[i].Time = flight[i].Distance / ports[i].Speed;
printf("distance airport is %f", flight[i].Time);
}
return 0;
}
double getDistance(double lat1, double long1, double lat2, double long2) {
double ret;
ret = acos(sin((deg2rad(lat1))) * sin(deg2rad(lat2)) + cos(deg2rad(lat1)) * cos(deg2rad(lat2)) * (cos(deg2rad(long1) - deg2rad(long2))));
ret = ret * 10800 / PI;
return ret;
}
double deg2rad(double deg) {
return (deg * PI / 180);
}
|