You are on page 1of 3

#include "SocialNetwork.

h" // constructor SocialNetwork::SocialNetwork() { } // implement the details here for each procedure void SocialNetwork::addPerson(string name, string group) { Person *poi; poi = new Person(name); persons.push_back(poi); poi->joinGroup(group); } void SocialNetwork::addGroup (string name, string group) { Group *poi; poi = new Group(group); groups.push_back(poi); poi->addMember(name); } string SocialNetwork::answerQuery1() { int currmax=0; string currstr="\n"; int i; for (i=0; i<groups.size(); i++) { if (groups[i]->getNumOfMembers() >= currmax ) { if ((groups[i]->getNumOfMembers() == currmax) && ( currstr > groups[i]->getName() || currstr=="\n" ) ) { currmax = groups[i]->getNumOfMembers(); currstr=groups[i]->getName(); } else if (groups[i]->getNumOfMembers() > currmax) { currmax = groups[i]->getNumOfMembers(); currstr=groups[i]->getName(); } } } return currstr; } string SocialNetwork::answerQuery2() { int currmax=0; string currstr="\n"; int i, j, k, l; string holder, holder1; for (i=0; i<persons.size(); i++) { for (j=0; j<persons[i]->getNumOfGroups(); j++) { holder=persons[i]->retrieve(j); for (k=0; k<groups.size(); k++) { if (groups[k]->getName()==holder) { break; } } for (l=0; l < groups[k]->getNumOfMembers(); l++) { holder1 = groups[k]->retrieve(l);

if (find(super.begin(), super.end(), holder1) == super.end()) super.push_back( holder1 ); } } // cout << currmax << "hey" << persons[i]->getName() << super.si ze() << endl; if ( super.size() >= currmax ) { if (super.size()==currmax && (persons[i]->getName() < currstr || currstr=="\n") ) { currmax=super.size(); currstr=persons[i]->getName(); } else if (super.size()>currmax) { currmax=super.size(); currstr=persons[i]->getName(); } } super.clear(); } return currstr; } void SocialNetwork::Createjoin(string name, string group) { int i; bool dupe=false; for (i=0; i<persons.size(); i++) { if (persons[i]->getName() == name) { dupe=true; persons[i]->joinGroup(group); } } if (dupe==false) addPerson(name, group); dupe=false; for (i=0; i<groups.size(); i++) if (groups[i]->getName() == group) { dupe = true; groups[i]->addMember(name); } if (dupe==false) addGroup(name, group); } void SocialNetwork::Quit(string name, string group) { int i; for (i=0; i<groups.size(); i++) if (groups[i]->getName() == group) { groups[i]->delMember(name); break; } for (i=0; i<persons.size(); i++) if (persons[i]->getName() == name) { persons[i]->quitGroup(group); break;

} } void SocialNetwork::Debug() { int i; for (i=0; i<persons.size(); i++) cout << "Person " << persons[i]->getName() << " has " << persons[i]->getNumOfGroups() << " groups." << endl; for (i=0; i<groups.size(); i++) cout << "Group " << groups[i]->getName() << " has " << groups[i]->getNumOfMembers() << " persons." << endl ; }