school/cs142/lab08/person.cpp

48 lines
1.1 KiB
C++
Raw Normal View History

2016-04-06 20:45:34 -07:00
#include <iostream>
#include <string>
using namespace std;
#include "person.h"
void person::modify_food(string new_food) {
fav_food = new_food;
}
void person::display_person(vector<person> & p) {
for(unsigned int i = 0; i < friends.size(); i++) {
for(unsigned int j = 0; j < p.size(); j++) {
if(p[j].name == friends[i] and p[j].fav_food == fav_food) {
cout << p[j].name << " also likes " << fav_food << endl;
}
}
}
}
void person::add_friend(string name) {
if(not already_friends(name)) {
friends.push_back(name);
}
}
bool person::already_friends(string name) {
for(unsigned int i = 0; i < friends.size(); i++) {
if(friends[i] == name) {
return true;
}
}
return false;
}
void person::delete_friend(string name) {
for(unsigned int i = 0; i < friends.size(); i++) {
if(friends[i] == name) {
friends.erase((friends.begin())+i);
break;
}
else {
cerr << "this person does not exist" << endl;
}
}
}