#include #include #include #include "place.h" const int Place::NO_ID=-1; Place::Place() : myStateID(NO_ID), myID(NO_ID), myType(NO_TYPE), myPop(0), myHousing(0), myLandArea(0), myWaterArea(0), myLatitude(0), myLongitude(0) // constructor { // Work done in initializer } Place::Place(int stateID, int ID, string name, PlaceType type, string state, int population, int housing, int landArea, int waterArea, double latitude, double longitude) : myStateID(stateID), myID(ID), myName(name), myType(type), myState(state), myPop(population), myHousing(housing), myLandArea(landArea), myWaterArea(waterArea), myLatitude(latitude), myLongitude(longitude) // constructor { // Work done in initializer } string Place::GetState() const // postcondition : returns state { return myState; } void Place::GetState(string & state, int & ID) const // postcondition : returns state and state ID { state = myState; ID = myStateID; } int Place::GetID() const // postcondition: returns ID of place { return myID; } string Place::GetName() const // postcondition: returns name of place { return myName; } int Place::GetLandArea() const // retuns land area of place { return myLandArea; } int Place::GetWaterArea() const // postcondition: returns water area of place { return myWaterArea; } void Place::GetCoordinates(double & latitude, double & longitude) const // postcondition: returns coordinates in Database format { latitude = myLatitude; longitude = myLongitude; } Place::PlaceType Place::GetPlaceType() const // returns place type { return myType; } void Place::Print(ostream & out) const // prints out place { const double ROUNDING_FACTOR = (0.5/3600); // 1/2 second for rounding double value; int degrees; // latitude int minutes; int seconds; char c; // N, S, E, or W // print out place out << myName << " " << myState << " " << myPop << " " << endl; // print out latitude value = myLatitude / 1000000 + ROUNDING_FACTOR; if (value >=0.0) { c = 'N'; } else { c = 'S'; value *=-1; } degrees = int (value); value -= double(degrees); value *= MINUTES_IN_DEGREE; minutes = int (value); value -= double(minutes); value *= SECONDS_IN_MINUTE; seconds = int (value); out << degrees << " deg " << minutes << " min " << seconds << " sec " << c << endl; // print out longitiude value = myLongitude / 1000000 + ROUNDING_FACTOR; if (value >=0.0) { c = 'E'; } else { c = 'W'; value *=-1; } degrees = int (value); value -= double(degrees); value *= MINUTES_IN_DEGREE; minutes = int (value); value -= double(minutes); value *= SECONDS_IN_MINUTE; seconds = int (value); out << degrees << " deg " << minutes << " min " << seconds << " sec " << c << endl; } ostream& operator<<(ostream& o, const Place & place) // prints out place { place.Print(o); return o; }