/* CS471B Assignment 2: University Instructor: Wade Holst Submitted by: Dan Fraser Student number: 001219229 File Name: Faculty.cc File description: Implementation of Faculty Composite class */ #include "Faculty.h" Faculty::~Faculty() { cout << "Faculty: destructor" << endl; // for each subcomponent, delete it vector::iterator p; for (p = _departments.begin() ; p != _departments.end() ; p++) { delete(*p); } } void Faculty::add(DepartmentComponent *f) { _departments.push_back(f); // add into the vector } void Faculty::del(DepartmentComponent *f) { vector::iterator p; // see if the thingy we want is in the vector if ((p = find(_departments.begin(), _departments.end(), f)) != _departments.end()) { // if it is, wipe it _departments.erase(p); } else { // if it isn't, warn! cout << "warning, tried to delete faculty but couldn't find it" << endl; } } // find the top mark in the collection int Faculty::getTopMark() const { vector::const_iterator p; int topMark = 0; for ( p = _departments.begin() ; p != _departments.end() ; p++) { if ((*p)->getTopMark() > topMark) { topMark = (*p)->getTopMark(); } } return topMark; } // find the number of students in the collection int Faculty::getTotalStudents() const { vector::const_iterator p; int totalStudents = 0; for ( p = _departments.begin() ; p != _departments.end() ; p++) { totalStudents += (*p)->getTotalStudents(); } return totalStudents; } // find the total number of people in the collection int Faculty::getTotalPeople() const { vector::const_iterator p; int totalPeople = 0; for ( p = _departments.begin() ; p != _departments.end() ; p++) { totalPeople += (*p)->getTotalPeople(); } return totalPeople; } // find the top professor in the collection Professor *Faculty::getTopProfessor() { vector::const_iterator p; Professor *topProfessor = NULL; int topSalary = 0; for ( p = _departments.begin() ; p != _departments.end() ; p++) { if ((*p)->getTopProfessor() != NULL) { if ((*p)->getTopProfessor()->getSalary() > topSalary) { topSalary = (*p)->getTopProfessor()->getSalary(); topProfessor = (*p)->getTopProfessor(); } } } if (topProfessor == NULL) cout << "warning, faculty returning null prof" << endl; return topProfessor; }