add solution of hw2
This commit is contained in:
86
hws/ride_sharing/Rider.cpp
Normal file
86
hws/ride_sharing/Rider.cpp
Normal file
@@ -0,0 +1,86 @@
|
||||
#include "Rider.h"
|
||||
#include <sstream>
|
||||
|
||||
Rider::Rider()
|
||||
: age(0), rating(0.0), pickupLatitude(0.0), pickupLongitude(0.0),
|
||||
dropoffLatitude(0.0), dropoffLongitude(0.0) {}
|
||||
|
||||
Rider::Rider(const std::string &fName, const std::string &lName,
|
||||
const std::string &gen, int a, const std::string &phone,
|
||||
double r, const std::string &pickupLocName, double pickupLat, double pickupLon,
|
||||
const std::string &dropoffLocName, double dropoffLat, double dropoffLon,
|
||||
const std::string &vPref, const std::string &state,
|
||||
const std::string &dF, const std::string &dL, const std::string &dP)
|
||||
: firstName(fName), lastName(lName), gender(gen), age(a),
|
||||
phoneNumber(phone), rating(r),
|
||||
pickupLocationName(pickupLocName), pickupLatitude(pickupLat), pickupLongitude(pickupLon),
|
||||
dropoffLocationName(dropoffLocName), dropoffLatitude(dropoffLat), dropoffLongitude(dropoffLon),
|
||||
vehiclePref(vPref), currentState(state),
|
||||
driverFirstName(dF), driverLastName(dL), driverPhoneNumber(dP) {}
|
||||
|
||||
const std::string& Rider::getFirstName() const { return firstName; }
|
||||
const std::string& Rider::getLastName() const { return lastName; }
|
||||
const std::string& Rider::getGender() const { return gender; }
|
||||
int Rider::getAge() const { return age; }
|
||||
const std::string& Rider::getPhoneNumber() const { return phoneNumber; }
|
||||
double Rider::getRating() const { return rating; }
|
||||
const std::string& Rider::getPickupLocationName() const { return pickupLocationName; }
|
||||
double Rider::getPickupLatitude() const { return pickupLatitude; }
|
||||
double Rider::getPickupLongitude() const { return pickupLongitude; }
|
||||
const std::string& Rider::getDropoffLocationName() const { return dropoffLocationName; }
|
||||
double Rider::getDropoffLatitude() const { return dropoffLatitude; }
|
||||
double Rider::getDropoffLongitude() const { return dropoffLongitude; }
|
||||
const std::string& Rider::getVehiclePref() const { return vehiclePref; }
|
||||
const std::string& Rider::getCurrentState() const { return currentState; }
|
||||
const std::string& Rider::getDriverFirstName() const { return driverFirstName; }
|
||||
const std::string& Rider::getDriverLastName() const { return driverLastName; }
|
||||
const std::string& Rider::getDriverPhoneNumber() const { return driverPhoneNumber; }
|
||||
|
||||
void Rider::setCurrentState(const std::string &state) {
|
||||
currentState = state;
|
||||
}
|
||||
|
||||
void Rider::setDriverInfo(const std::string &df, const std::string &dl, const std::string &dp) {
|
||||
driverFirstName = df;
|
||||
driverLastName = dl;
|
||||
driverPhoneNumber = dp;
|
||||
}
|
||||
|
||||
std::string Rider::toFileString() const {
|
||||
//Isabella
|
||||
//Richard
|
||||
//Female
|
||||
//39
|
||||
//301-144-6533
|
||||
//3.2
|
||||
//Top_of_the_Rock
|
||||
//40.7593 -73.979
|
||||
//Gowanus
|
||||
//40.6733
|
||||
//-73.99
|
||||
//Economy
|
||||
//Ready_to_request
|
||||
//null
|
||||
//null
|
||||
//null
|
||||
std::ostringstream oss;
|
||||
oss << firstName << " "
|
||||
<< lastName << " "
|
||||
<< gender << " "
|
||||
<< age << " "
|
||||
<< phoneNumber << " "
|
||||
<< rating << " "
|
||||
<< pickupLocationName << " "
|
||||
<< pickupLatitude << " "
|
||||
<< pickupLongitude << " "
|
||||
<< dropoffLocationName << " "
|
||||
<< dropoffLatitude << " "
|
||||
<< dropoffLongitude << " "
|
||||
<< vehiclePref << " "
|
||||
<< currentState << " "
|
||||
<< (driverFirstName.empty() ? "null" : driverFirstName) << " "
|
||||
<< (driverLastName.empty() ? "null" : driverLastName) << " "
|
||||
<< (driverPhoneNumber.empty() ? "null" : driverPhoneNumber);
|
||||
|
||||
return oss.str();
|
||||
}
|
||||
Reference in New Issue
Block a user