// File: State.cpp // Description: Implementation file for class State member functions #include #include #include "Date.h" #include "State.h" using namespace std; // default constructor State::State() { stateName=stateCapital=""; popDensity=0; popRank=areaRank=0; admittOrder=totalPop=area=0; } /* * function: getName * * parameters: None * * returns: string stateName * */ string State::getName() { return(stateName); } /* * function: getCap * * parameters: None * * returns: string stateCapital * */ string State::getCap() { return(stateCapital); } /* * function: getPopRank * * parameters: None * * returns: int popRank * */ int State::getPopRank() { return(popRank);} /* * function: getAreaRank * * parameters: None * * returns: int getAreaRank * */ int State::getAreaRank() { return(areaRank);} /* * function: getAdmitOrder * * paraemters: None * * returns: int admittOrder * */ int State::getAdmitOrder() { return(admittOrder);} //function returns a state's population long State::getPop() { return(totalPop); } // operator overloading for a state name and attribute input istream &operator>>(istream &Source, State &s) { int mm, dd, yyyy; //month, day, and year of admission char nullToken; //gets the space before the capital getline(Source,s.stateName); Source>>s.totalPop >> s.popRank >> s.popDensity; Source>>s.area>>s.areaRank>>mm>>dd>>yyyy; s.AdmDate.setDate(mm,dd,yyyy); Source>>s.admittOrder; Source.get(nullToken); //used to get the blank before the stateCapital getline (Source, s.stateCapital); string dummy; for (int i=0;i<5;i++) getline(Source,dummy); return Source; } // compare state names (for sorting) bool State::operator<(const State& s) const { return (stateName < s.stateName); } /* * function: operator< (string) * * parameters: const string& s: String to be compared with State object * * Description: overloaded < operator that compares a State object with a * string for use with the STL find() function * * returns: bool * */ bool State::operator<(const string& s) const { return(stateName < s); } // check for equality of state name and a key bool State::operator==(string searchTerm) { return (stateName == searchTerm); } // check for equality of state name and another State bool State::operator==(State searchTerm) { return (stateName == searchTerm.stateName); } // Is the state name large than the key? bool State::operator>(string searchTerm) { return (stateName > searchTerm); } // operator overload for state name and attribute output ostream &operator<<(ostream &Destination, const State &s) { Destination.setf(ios::left); Destination<