/* CS471B Assignment 2: University Instructor: Wade Holst Submitted by: Dan Fraser Student number: 001219229 File Name: University.cc File description: University aggregate class implementation */ #include "University.h" // initialize our instance University* University::_instance = 0; // meat of the singleton... lazy initalization of // our class! University* University::Instance() { if (_instance == 0) { cout << "creating new university" << endl; _instance = new University; } return _instance; } University::~University() { // delete ourself and our components cout << "University: destructor" << endl; vector::iterator p; for (p = _faculties.begin() ; p != _faculties.end() ; p++) { delete(*p); } } void University::add(FacultyComponent *f) { _faculties.push_back(f); // add to the vector } void University::del(FacultyComponent *f) { vector::iterator p; // see if f is in the vector if ((p = find(_faculties.begin(), _faculties.end(), f)) != _faculties.end()) { // if it is, delete it _faculties.erase(p); } else { // if it isn't, warn! cout << "warning, tried to delete faculty but couldn't find it" << endl; } } int University::getTopMark() const { vector::const_iterator p; int topMark = 0; for ( p = _faculties.begin() ; p != _faculties.end() ; p++) { if ((*p)->getTopMark() > topMark) { topMark = (*p)->getTopMark(); } } return topMark; } int University::getTotalStudents() const { vector::const_iterator p; int totalStudents = 0; for ( p = _faculties.begin() ; p != _faculties.end() ; p++) { totalStudents += (*p)->getTotalStudents(); } return totalStudents; } int University::getTotalPeople() const { vector::const_iterator p; int totalPeople = 0; for ( p = _faculties.begin() ; p != _faculties.end() ; p++) { totalPeople += (*p)->getTotalPeople(); } return totalPeople; } Professor* University::getTopProfessor() const { vector::const_iterator p; Professor *topProfessor = NULL; int topSalary = 0; for ( p = _faculties.begin() ; p != _faculties.end() ; p++) { if ((*p)->getTopProfessor() != NULL) { if ((*p)->getTopProfessor()->getSalary() > topSalary) { topSalary = (*p)->getTopProfessor()->getSalary(); topProfessor = (*p)->getTopProfessor(); } } } return topProfessor; }