adding cs142 code
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user