/* CS471B Assignment 2: University Instructor: Wade Holst Submitted by: Dan Fraser Student number: 001219229 File Name: Department.cc File description: Implementaton of Department Composite Class */ #include "Department.h" Department::~Department() { cout << "Department: destructor" << endl; // delete all the stuff we've stored! vector::iterator p; for (p = _people.begin() ; p != _people.end() ; p++) { delete(*p); } } void Department::add(Person *f) { // add the person to our vector _people.push_back(f); } void Department::del(Person *f) { // find the person and delete her... warn if something // went wrong vector::iterator p; if ((p = find(_people.begin(), _people.end(), f)) != _people.end()) { _people.erase(p); } else { cout << "warning, tried to delete person but couldn't find it" << endl; } } int Department::getTopMark() const { vector::const_iterator p; int topMark = 0; // for each person for ( p = _people.begin() ; p != _people .end() ; p++) { // if they have the highest mark if ((*p)->getTopMark() > topMark) { // record that mark topMark = (*p)->getTopMark(); } } return topMark; } Professor *Department::getTopProfessor() { vector::const_iterator p; Professor *topProfessor = NULL; int topSalary = 0; for ( p = _people.begin() ; p != _people.end() ; p++) { if ((*p)->getTopProfessor() != NULL) { if ((*p)->getTopProfessor()->getSalary() > topSalary) { topSalary = (*p)->getTopProfessor()->getSalary(); topProfessor = (*p)->getTopProfessor(); } } } if (topProfessor == NULL) cout << "warning, department returning null prof" << endl; return topProfessor; } int Department::getTotalStudents() const { vector::const_iterator p; int totalStudents = 0; for ( p = _people.begin() ; p != _people.end() ; p++) { totalStudents += (*p)->getTotalStudents(); } return totalStudents; } int Department::getTotalPeople() const { vector::const_iterator p; int totalPeople = 0; for ( p = _people.begin() ; p != _people.end() ; p++) { totalPeople += (*p)->getTotalPeople(); } return totalPeople; }