Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Programming C++ Programming Hi! Sorry for all the material attached. I simply need help in writing the Runway.cpp file and the other files are

C++ Programming

C++ Programming

Hi! Sorry for all the material attached. I simply need help in writing the Runway.cpp file and the other files are included in case they're needed for understanding. I was able to complete the mayday.cpp file but am stuck on Runway. Not sure if Facilitiy.cpp is required, I am still working on that one. The following link contains a tar file with the files provided by the professor. Thank you so much in advanced!

http://web.cs.ucdavis.edu/~fgygi/ecs40/homework/hw4/

image text in transcribedimage text in transcribedimage text in transcribed

Closer.h:

#ifndef CLOSER_H

#define CLOSER_H

#include

#include "gcdistance.h"

struct Closer {

const double latitude, longitude;

Closer(const double ¤t_latitude, const double ¤t_longitude)

: latitude(current_latitude), longitude(current_longitude) {}

bool operator()(const Facility* a, const Facility* b) {

return (gcdistance(a->latitude(), a->longitude(), latitude, longitude)

latitude(), b->longitude(), latitude, longitude));

}

};

#endif

mayday.cpp

//

// mayday.cpp

//

// use: mayday latitude longitude min_length

//

// Provide a list of facilities and runways closest to the location specified

// by the coordinates (latitude,longitude).

// Only facilities having runways longer than min_length are printed.

// Only runways longer than min_length are printed.

//

// Input:

// latitude, longitude in degrees decimal

// min_length in ft

// Output:

// list of nearest facilities and runways including distance in nautical miles

#include "Facility.h"

#include "Runway.h"

#include "gcdistance.h"

#include "Closer.h"

#include "SiteNumber.h"

#include

#include

#include

#include

#include

#include

#include

#include

#include

using namespace std;

#define M_PI 3.14159265358979323846

double gcdistance(double lat1, double lon1, double lat2, double lon2) {

// convert latitudes and longitudes from degrees to radians

const double lat1r = lat1 * (M_PI/180.0);

const double lon1r = lon1 * (M_PI/180.0);

const double lat2r = lat2 * (M_PI/180.0);

const double lon2r = lon2 * (M_PI/180.0);

// psi = central angle between the points (lat1,lon1) and

// (lat2,lon2) on a sphere

double c = cos(lat1r)*cos(lat2r)*cos(lon1r-lon2r) + sin(lat1r)*sin(lat2r);

// truncate possible numerical errors in cos to [-1,1] interval

c = fmin(c,1.0);

c = fmax(c,-1.0);

const double psi = acos(c);

// R_Earth = 6371 km

// 1 NM = 1.852 km

// 1 degree = 60.0405 NM on a great circle

return 60.0405 * psi * (180.0/M_PI);

}

double Facility::convert_latitude(string s) const {

bool doNegative = false;

if(s[s.length() - 1] == 'S') {

doNegative = true;

}

s = s.substr(0, s.length() - 1);

double temp = atof(s.c_str())/3600.00;

return (doNegative ? (-1 * temp) : temp);

}

double Facility::convert_longitude(string s) const {

bool doNegative = false;

if(s[s.length() - 1] == 'W') {

doNegative = true;

}

s = s.substr(0, s.length() - 1);

double temp = atof(s.c_str())/3600.00;

return (doNegative ? (-1 * temp) : temp);

}

Facility::Facility(string s) {

if(s.length() != 0) {

site_number_ = s.substr(0, 11);

type_ = s.substr(11, 13);

code_ = s.substr(24, 4);

name_ = s.substr(130, 50);

latitude_ = convert_latitude(s.substr(535, 12));

longitude_ = convert_longitude(s.substr(562, 12));

}

}

string Facility::site_number(void) const {

return site_number_;

}

string Facility::type(void) const {

return type_;

}

string Facility::code(void) const {

return code_;

}

string Facility::name(void) const {

return name_;

}

double Facility::latitude(void) const {

return latitude_;

}

double Facility::longitude(void) const {

return longitude_;

}

double Facility::distance(double lat, double lon) const {

return gcdistance(lat, lon, latitude(), longitude());

}

int Runway::convert_length(string s) const {

return atoi(s.c_str());

}

Runway::Runway(string s) {

if(s.length() != 0) {

site_number_ = s.substr(0, 11);

name_ = s.substr(13, 7);

length_ = convert_length(s.substr(20, 5));

}

}

string Runway::site_number(void) const {

return site_number_;

}

string Runway::name(void) const {

return name_;

}

int Runway::length(void) const {

return length_;

}

int main(int argc, char **argv) {

// use: mayday current_latitude current_longitude min_runway_length

// latitude and longitudes in degrees decimal

// min runway length of runway in ft

assert(argc==4);

const double current_latitude = atof(argv[1]);

const double current_longitude = atof(argv[2]);

const int min_runway_length = atoi(argv[3]);

string line;

vector facilities;

// load facilities data

ifstream inputFile;

inputFile.open("Facilities.txt");

if(!inputFile) {

cout

exit(0);

}

line = "";

while(getline(inputFile, line)) {

if(line.length() != 0) {

Facility* tempFacility = new Facility(line);

facilities.push_back(tempFacility);

}

}

inputFile.close();

// sort facilities in order of proximity to the current position

sort(facilities.begin(), facilities.end(),

Closer(current_latitude,current_longitude));

vector runways;

// load runways data

inputFile.open("Runways.txt");

if(!inputFile) {

cout

exit(0);

}

line = "";

while(getline(inputFile, line)) {

if(line.length() != 0) {

Runway* tempRunway = new Runway(line);

runways.push_back(tempRunway);

}

}

inputFile.close();

// list up to 10 nearest facilities that have a long enough runway

// list each runway that is long enough

int count = 0;

for ( unsigned int i = 0; i

Facility *a = facilities[i];

// Find all runways of this facility that are long enough

vector good_runways;

vector temp_good_runways = SiteNumber(a->site_number(), runways);

for(unsigned int j = 0; j

if(temp_good_runways[j]->length() >= min_runway_length) {

good_runways.push_back(temp_good_runways[j]);

}

}

// print this facility if it has long enough runways

if ( !good_runways.empty() ) {

// increment count of good facilities

count++;

cout type() code()

name()

cout.setf(ios_base::fixed,ios_base::floatfield);

cout.setf(ios_base::right, ios_base::adjustfield);

cout.width(5);

cout.precision(1);

cout distance(current_latitude,current_longitude)

// print all runways that are long enough

for ( unsigned int i = 0; i

Runway *r = good_runways[i];

cout name() length()

}

}

}

}

SiteNumber.h

#ifndef SITE_NUMBER_H

#define SITE_NUMBER_H

#include

#include

std::vector SiteNumber(std::string s, std::vector runways) {

std::vector good_runways;

for(int i = 0; i

if(runways[i]->site_number() == s) {

good_runways.push_back(runways[i]);

}

}

return good_runways;

}

#endif

testFacility.cpp

#include "Facility.h"

#include "gcdistance.h"

#include "gcdistance.cpp"

#include

#include

#include

#include

#include

using namespace std;

double Facility::convert_latitude(string s) const {

bool doNegative = false;

if(s[s.length() - 1] == 'S') {

doNegative = true;

}

s = s.substr(0, s.length() - 1);

double temp = atof(s.c_str())/3600.00;

return (doNegative ? (-1 * temp) : temp);

}

double Facility::convert_longitude(string s) const {

bool doNegative = false;

if(s[s.length() - 1] == 'W') {

doNegative = true;

}

s = s.substr(0, s.length() - 1);

double temp = atof(s.c_str())/3600.00;

return (doNegative ? (-1 * temp) : temp);

}

Facility::Facility(string s) {

if(s.length() != 0) {

site_number_ = s.substr(0, 11);

type_ = s.substr(11, 13);

code_ = s.substr(24, 4);

name_ = s.substr(130, 50);

latitude_ = convert_latitude(s.substr(535, 12));

longitude_ = convert_longitude(s.substr(562, 12));

}

}

string Facility::site_number(void) const{

return site_number_;

}

string Facility::type(void) const{

return type_;

}

string Facility::code(void) const{

return code_;

}

string Facility::name(void) const{

return name_;

}

double Facility::latitude(void) const{

return latitude_;

}

double Facility::longitude(void) const{

return longitude_;

}

double Facility::distance(double lat, double lon) const{

return gcdistance(lat, lon, latitude(), longitude());

}

int main() {

string line;

ifstream inputFile;

// Change the file name to test various cases

inputFile.open("testFacility1.in");

getline(inputFile, line);

Facility f(line);

cout

cout

cout

}

testRunway.cpp

#include "Runway.h"

#include

#include

#include

#include

using namespace std;

int Runway::convert_length(string s) const {

return atoi(s.c_str());

}

Runway::Runway(string s) {

if(s.length() != 0) {

site_number_ = s.substr(0, 11);

name_ = s.substr(13, 7);

length_ = convert_length(s.substr(20, 5));

}

}

string Runway::site_number(void) const {

return site_number_;

}

string Runway::name(void) const {

return name_;

}

int Runway::length(void) const {

return length_;

}

int main() {

string line;

ifstream inputFile;

// Change the file name to test various cases

inputFile.open("testRunway1.in");

getline(inputFile, line);

Runway r(line);

cout

}

Emergency landing application Description In this assignment (HW4), you will implement a program called mayday that prints alist of airports and runways that are closest to a given location. The program will list airports that have runways longer than a given minimum length. It will also print the distance from the given location to the airport. In a fictional scenario, a pilot who encounters an emergency situation would use your program to get a list of the nearest landing options. The pilot would enter hisher current location as latitude and longitude (in degrees decimal as well as the minimum runway length needed to land (in ft). This assignment will test your C++proficiency in opening and reading text files, using strings, using STL containers, using STL algorithms, and implementing function objects. Program The program will read data from two text files containing information about Federal Aviation Administration (FAA facilities and runways. The files Facilities txt and Runways .txt are provided and contain a list of 19700 facilities (such as airports, heliports, seaplane bases) and 23595 nunways located mostly in the United States, but also in remote locations Each line in the Facilities txt file contains the description of a facility (airport, heliport or seaplane base), The first part of the line contains the site number, a 10-character string that uniquely identifies the facility. The rest ofthe line contains other information, including the facility type, name, code, and position (latitude and longitude in various formats). For example, San Francisco Intemational Airport has site number 02187. A type AIRPORT code SFO. name SAN FRANCISCO INTL, latitude 135427.700ON and longitude 440551. 5000W (expressed in seconds deci The positions of these fields in the line are: Site number: haracters haracters 12-24 Type: Code characters 25-28 Name: 80 Latitude (sec decimal characters 536-547 Longitude (see decimal characters 563-574 Other fields are not relevant to this assignment. Each line in the Runways. takt file contains the description of arunway. The first part ofthe line contains the site number ofthe facility it belongs to (i.e. the 10-character string described above). The rest of the line contains other information about the runway, including its name and length (in feet). For example, runway 10L28R of San Francisco International airport has site number 02187. A name 10L/28R. and a length of 11870 ft. The positions of these fields in the line are: Site number: characters

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_2

Step: 3

blur-text-image_3

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

Master The Art Of Data Storytelling With Visualizations

Authors: Alexander N Donovan

1st Edition

B0CNMD9QRD, 979-8867864248

More Books

Students also viewed these Databases questions