school/cs142/smcquay/lab08/person.cc
2016-04-06 20:45:34 -07:00

54 lines
1.2 KiB
C++

using namespace std;
#include "person.h"
void person::update_food(string new_food) {
if(name != "Kevin Bacon")
favorite_food = new_food;
}
void person::food_friend() {
cout << "freinds for " << this->name << " with similar tastes: [";
for(auto i = friends.begin(); i != friends.end(); i++) {
if((*i)->favorite_food == this->favorite_food) {
cout << "'" << (*i)->name << "', ";
}
}
cout << "]" << endl;
}
int person::bacon_number() {
return 0;
}
ostream &operator<<(ostream &stream, person & p) {
stream << "{name: '" << p.name
<< "', favorite_food: '" << p.favorite_food
<< "'";
if(p.friends.size() > 0) {
stream << ", friends: [";
for(auto i = p.friends.begin(); i != p.friends.end(); i++) {
if (i != p.friends.begin()) {
stream << ", ";
}
stream << "'" << (*i)->name << "'";
}
stream << "]";
}
stream << "}";
return stream;
}
istream &operator>>(istream &stream, person &o) {
string buffer;
cout << "name: ";
stream.ignore();
getline(stream, buffer);
o.name = buffer;
cout << "food: ";
getline(stream, buffer);
o.favorite_food = buffer;
return stream;
}