Question

Runway Runway(string s) The constructor takes a single string argument. The argument s contains a full...

Runway

Runway(string s)
The constructor takes a single string argument. The argument s contains a full line read from the Runways.txt file. The constructor should initialize the data members of Runway by selecting the appropriate substrings from the argument.

string site_number(void) const

This function returns the site number of the facility that the runway belongs to.

string name(void) const

This function returns the name of the runway.

int length(void) const

This function returns the length of the runway in ft.

int convert_length(string s) const
This function converts the string s representing a runway length to an int value in feet.

//
// Runway.h
//

#ifndef RUNWAY_H
#define RUNWAY_H
#include<string>
class Runway
{
public:
Runway(std::string s);
std::string site_number(void) const;
std::string name(void) const;
int length(void) const;
private:
int convert_length(std::string s) const;
const std::string site_number_;
const std::string name_;
const int length_;
};
#endif

testRunway.cpp

//
// testRunway.cpp
//

#include "Runway.h"
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
string line;
getline(cin,line);
Runway r(line);
cout << r.site_number() << " " << r.name() << " "
<< setw(8) << r.length() << endl;
}

Example of Code: testRunway.in

04508.*A IL09R/27L 7967 150ASPH-CONC-G GRVD 108/R/C/W/UHIGH 09R090ILS/DME NPIR G41-59-02.0302N 151142.0302N087-55-06.0672W316506.0672W 659.8 743.00 659.8P4L TMRNMALSR NYY PIR 50 27L270ILS/DME NPIR G41-59-02.0405N 151142.0405N087-53-20.5834W316400.5834W 650.1 673.00 653.6P4R TMRNALSF2 NYYRR PIR 42 34 162944R 3RD PARTY SURVEY07/27/2012 100.0 210.0 350.0 0.1 3RD PARTY SURVEY07/27/20123RD PARTY SURVEY07/27/2012 3RD PARTY SURVEY07/27/2012 7967 7967 7709 7709 0.1 3RD PARTY SURVEY07/27/20123RD PARTY SURVEY07/27/2012 3RD PARTY SURVEY07/27/2012 7967 7967 7782 7782

testRunway.out

04508.*A 09R/27L 7967

0 0
Add a comment Improve this question Transcribed image text
Answer #1

//testRunway.cpp
#include "Runway.h"
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
string line;
getline(cin,line);
Runway r(line);
cout << r.site_number() << " " << r.name() << " "
       << setw(8) << r.length() << endl;
}
---------------------------------------------------------------------
//testFacility.cpp
#include "Facility.h"
#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
string line;
getline(cin,line);
Facility f(line);
cout << f.site_number() << " " << f.type() << " " << f.code() << " "
       << f.name() << " ";
cout << setw(12) << setprecision(4) << fixed << f.latitude() << " "
       << setw(12) << setprecision(4) << fixed << f.longitude() << " ";
cout << f.distance(40,-100) << endl;
}
----------------------------------------------------------------------------------------------
//mayday.cpp
#include "Facility.h"
#include "Runway.h"
#include "Closer.h"
#include "SiteNumber.h"
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <vector>
#include <cassert>
#include <cmath>
using namespace std;

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]);

vector<Facility*> facilities;
// load facilities data
// Insert your code here

ifstream facilityfile("Facilities.txt");

string line1;
while(getline(facilityfile,line1))
{
      Facility* ff = new Facility(line1);
      facilities.push_back(ff);
}

  
// sort facilities in order of proximity to the current position
sort(facilities.begin(), facilities.end(),
       Closer(current_latitude,current_longitude));
  


vector<Runway*> runways;
// load runways data
// Insert your code here

    ifstream runwayfile("Runways.txt");
  
    string line2;
    while(getline(runwayfile,line2))
    {
        Runway* rf = new Runway(line2);
        runways.push_back(rf);
    }

// 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 < facilities.size() && count < 10; i++ )
{
    Facility *a = facilities[i];

    // Find all runways of this facility that are long enough
    vector<Runway*> good_runways;
    // Insert your code here

      for(vector<Runway*>::iterator it = find_if(runways.begin(),runways.end(),SiteNumber(a->site_number())); it != runways.end(); it = find_if(++it,runways.end(),SiteNumber(a->site_number())))
    {
      if((*it)->length() >= min_runway_length) good_runways.push_back(*it);
    }
    // print this facility if it has long enough runways
    if ( !good_runways.empty() )
    {
      // increment count of good facilities
      count++;

      cout << a->type() << " " << a->code() << " "
           << a->name() << " ";
      cout.setf(ios_base::fixed,ios_base::floatfield);
      cout.setf(ios_base::right, ios_base::adjustfield);
      cout.width(5);
      cout.precision(1);
      cout << a->distance(current_latitude,current_longitude)
           << " NM" << endl;

      // print all runways that are long enough
      for ( unsigned int i = 0; i < good_runways.size(); i++ )
      {
        Runway *r = good_runways[i];
        cout << " Runway: " << r->name() << " length: " << r->length()
             << " ft" << endl;
      }
    }
}
}
-----------------------------------------------------------------------------------------------
//gcdistance.cpp
#include "gcdistance.h"
#include <cmath>
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);
}
--------------------------------------------------------------------------------------
//gcdistance.h
#ifndef GCDISTANCE_H
#define GCDISTANCE_H
double gcdistance(double lat1, double lon1, double lat2, double lon2);
#endif
-----------------------------------------------------------------------------------
//SiteNumber.h
#ifndef SITENUMBER_H
#define SITENUMBER_H
#include "Runway.h"
#include "Facility.h"

class SiteNumber
{
public:
    SiteNumber(std::string site_number): snum(site_number) {}
    bool operator() (Runway* r) { return r->site_number() == snum; }
private:
    const std::string snum;
};

#endif
----------------------------------------------------------------------------
//RunWay.cpp
#include <iostream>
#include <sstream>
#include "Runway.h"

Runway::Runway(std::string s): site_number_(s.substr(0,10)), name_(s.substr(13,7)), length_(convert_length(s)) {}

std::string Runway::site_number(void) const
{
    return site_number_;
}

std::string Runway::name(void) const
{
    return name_;
}

int Runway::length(void) const
{
    return length_;
}

int Runway::convert_length(std::string s) const
{
    std::istringstream is(s.substr(20,5));
    int len;
    is >> len;
    return len;
}
-------------------------------------------------------------------------
//Runway.h
#ifndef RUNWAY_H
#define RUNWAY_H
#include<string>
class Runway
{
public:
    Runway(std::string s);
    std::string site_number(void) const;
    std::string name(void) const;
    int length(void) const;
private:
    int convert_length(std::string s) const;
    const std::string site_number_;
    const std::string name_;
    const int length_;
};
#endif
------------------------------------------------------------------
//Facility.cpp
#include <iostream>
#include <string>
#include <sstream>
#include "Facility.h"
#include "gcdistance.h"

Facility::Facility(std::string s) : site_number_(s.substr(0,10)), type_(s.substr(11,13)), code_(s.substr(24,4)), name_(s.substr(130,50)), latitude_(Facility::convert_latitude(s)), longitude_(Facility::convert_longitude(s)) {}

std::string Facility::site_number(void) const
{
    return site_number_;
}

std::string Facility::type(void) const
{
    return type_;
}

std::string Facility::code(void) const
{
    return code_;
}

std::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(latitude_,longitude_,lat,lon);
}

double Facility::convert_latitude(std::string s) const
{
    std::istringstream is1(s.substr(535,11));
    double la;
    is1 >> la;
    if(s.substr(546,1) == "S") la *= -1;
    return la/3600;
}
double Facility::convert_longitude(std::string s) const
{
    std::istringstream is2(s.substr(562,11));
    double lo;
    char dir2;
    is2 >> lo >> dir2;
    if(s.substr(573,1) == "W") lo *= -1;
    return lo/3600;
}
----------------------------------------------------------------------------------
//Facility.h
#ifndef FACILITY_H
#define FACILITY_H
#include<string>
class Facility
{
public:
    Facility(std::string s);
    std::string site_number(void) const;
    std::string type(void) const;
    std::string code(void) const;
    std::string name(void) const;
    double latitude(void) const;
    double longitude(void) const;
    double distance(double lat, double lon) const;
private:
    const std::string site_number_;
    const std::string type_;
    const std::string code_;
    const std::string name_;
    const double latitude_, longitude_;
    double convert_latitude(std::string s) const;
    double convert_longitude(std::string s) const;
};
#endif
-------------------------------------------------------------------------------
//Closer.h
#ifndef CLOSER_H
#define CLOSER_H

#include "Facility.h"

class Closer
{
public:
    Closer(double current_latitude, double current_longitude): lat(current_latitude), lon(current_longitude) {}
    bool operator() (Facility* f1, Facility* f2) { return f1->distance(lat,lon) < f2->distance(lat,lon); }
private:
    const double lat;
    const double lon;
};

#endif

Add a comment
Know the answer?
Add Answer to:
Runway Runway(string s) The constructor takes a single string argument. The argument s contains a full...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Greetings, everybody I already started working in this program. I just need someone to help me...

    Greetings, everybody I already started working in this program. I just need someone to help me complete this part of the assignment (my program has 4 parts of code: main.cpp; Student.cpp; Student.h; StudentGrades.cpp; StudentGrades.h) Just Modify only the StudentGrades.h and StudentGrades.cpp files to correct all defect you will need to provide implementation for the copy constructor, assignment operator, and destructor for the StudentGrades class. Here are my files: (1) Main.cpp #include <iostream> #include <string> #include "StudentGrades.h" using namespace std; int...

  • C++ 1. The copy constructor is used for one the following scenarios: I. Initialize one object...

    C++ 1. The copy constructor is used for one the following scenarios: I. Initialize one object from another of the same type. II. Copy an object to pass it as argument to a function. III. Copy an object to return it from a function. Read the following program and answer questions (20 points) #include <iostream> using namespace std; class Line public: int getLength( void); Line( int len // simple constructor Line( const Line &obj) 1/ copy constructor Line (); //...

  • C++ Programming Hi! Sorry for all the material attached. I simply need help in writing the...

    C++ Programming Hi! Sorry for all the material attached. I simply need help in writing the Facility.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 Facility. 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/ Closer.h: #ifndef CLOSER_H #define CLOSER_H #include <string> #include "gcdistance.h" struct Closer { const double latitude, longitude;...

  • This is a simple C++ class using inheritance, I have trouble getting the program to work....

    This is a simple C++ class using inheritance, I have trouble getting the program to work. I would also like to add ENUM function to the class TeachingAssistant(Derived class) which is a subclass of Student(Derived Class) which is also a subclass of CourseMember(Base Class). The TeachingAssistant class uses an enum (a user-defined data type) to keep track of the specific role the TA has: enum ta_role {LAB_ASSISTANT, LECTURE_ASSISTANT, BOTH}; You may assume for initialization purposes that the default role is...

  • C++ LinkedList I need the code for copy constructor and assignment operator #include <iostream> #include <string> using namespace std; typedef string ItemType; struct Node {    ItemType va...

    C++ LinkedList I need the code for copy constructor and assignment operator #include <iostream> #include <string> using namespace std; typedef string ItemType; struct Node {    ItemType value;    Node *next; }; class LinkedList { private:    Node *head;    // You may add whatever private data members or private member functions you want to this class.    void printReverseRecursiveHelper(Node *temp) const; public:    // default constructor    LinkedList() : head(nullptr) { }    // copy constructor    LinkedList(const LinkedList& rhs);    // Destroys all the dynamically allocated memory    //...

  • C++ When running my tests for my char constructor the assertion is coming back false and...

    C++ When running my tests for my char constructor the assertion is coming back false and when printing the string garbage is printing that is different everytime but i dont know where it is wrong Requirements: You CANNOT use the C++ standard string or any other libraries for this assignment, except where specified. You must use your ADT string for the later parts of the assignment. using namespace std; is stricly forbiden. As are any global using statements. Name the...

  • C++ PLEASE Provide a class for authoring a simple letter. In the constructor, supply the names...

    C++ PLEASE Provide a class for authoring a simple letter. In the constructor, supply the names of the sender and the recipient. The header file for this class is given below. #ifndef LETTER_H #define LETTER_H #include #include using namespace std; class Letter { public:    //constructor    Letter(string from = "John", string to = "Ana");    void add_line(string line);    string get_text() const; private:    string sender;    string recipient;    vector lines; }; #endif -Implement the constructor to initialize...

  • Write a function that takes a string parameter and determines whether the string contains matching grouping...

    Write a function that takes a string parameter and determines whether the string contains matching grouping symbols. Grouping symbols are parenthesis ( ) , brackets [] and curly braces { }. For example, the string {a(b+ac)d[xy]g} and kab*cd contain matching grouping symbols. However, the strings ac)cd(e(k, xy{za(dx)k, and {a(b+ac}d) do not contain matching grouping symbols. (Note: open and closed grouping symbols have to match both in number and in the order they occur in the string). Your function must use...

  • CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer;...

    CODES: main.cpp #include <iostream> #include <string> #include "ShoppingCart.h" using namespace std; char PrintMenu() { char answer; cout << "MENU" << endl; cout << "a - Add item to cart" << endl; cout << "d - Remove item from cart" << endl; cout << "c - Change item quantity" << endl; cout << "i - Output items' descriptions" << endl; cout << "o - Output shopping cart" << endl; cout << "q - Quit" << endl << endl; while (true) {...

  • This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a fun...

    This is for my c++ class and im stuck. Complete the Multiplex.cpp file with definitions for a function and three overloaded operators. You don't need to change anything in the Multiplex.h file or the main.cpp, though if you want to change the names of the movies or concession stands set up in main, that's fine. Project Description: A Multiplex is a complex with multiple movie theater screens and a variety of concession stands. It includes two vectors: screenings holds pointers...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT