-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAirport.cpp
53 lines (40 loc) · 1.32 KB
/
Airport.cpp
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
#include "Airport.h"
#include <utility>
#include <cmath>
Airport::Airport(): latitude_(0.0), longitude_(0.0) {}
Airport::Airport(string code): code_(std::move(code)) {}
Airport::Airport(string code, string name, string city, string country, float latitude, float longitude):
code_(std::move(code)), name_(std::move(name)), city_(std::move(city)), country_(std::move(country)),
latitude_(latitude), longitude_(longitude) {}
string Airport::getCode() const {
return code_;
}
string Airport::getName() {
return name_;
}
string Airport::getCity() {
return city_;
}
string Airport::getCountry() {
return country_;
}
double Airport::getLatitude() const {
return latitude_;
}
double Airport::getLongitude() const {
return longitude_;
}
double Airport::calculateDistance(Airport* a2) const {
double dLat = (a2->getLatitude() - this->getLatitude()) * M_PI / 180.0;
double dLon = (a2->getLongitude() - this->getLongitude()) * M_PI / 180.0;
// convert to radians
double lat1Rad = this->getLatitude() * M_PI / 180.0;
double lat2Rad = a2->getLatitude() * M_PI / 180.0;
// apply formulae
double a = pow(sin(dLat / 2), 2) +
pow(sin(dLon / 2), 2) *
cos(lat1Rad) * cos(lat2Rad);
double rad = 6371.0;
double c = 2.0 * asin(sqrt(a));
return round(rad * c);
}