#include "Teacher.h" Teacher::Teacher(void) { numStudents = 0; setName(("default teacher")); myFavorites = new Student*[ MAX_FAVORITES ]; for (int i = 0; i < MAX_FAVORITES; i++) { myFavorites[i] = NULL; } } Teacher::Teacher(string teacher_name) { numStudents = 0; setName(teacher_name); myCourse = NULL; myFavorites = new Student*[ MAX_FAVORITES ]; for (int i = 0; i < MAX_FAVORITES; i++) myFavorites[i] = NULL; } Teacher::~Teacher(void) { myCourse->removeTeacher(); delete myFavorites; } void Teacher::addToMyFavorites(Student *fav) { bool inclass = false; for (int i = 0; i < myCourse->getCapacity(); i++) { if (myCourse->students[i] == fav) inclass = true; } if (inclass) { for (int i = 0; i < Teacher::MAX_FAVORITES; i++) { if (!myFavorites[i]) { myFavorites[i] = fav; return; } else if (myFavorites[i] == fav) cout << fav->getName() << " is already a favorite of " << name << endl; } cout << name << " already has too many favorites" << endl; } else { cout << fav->getName() << " is not in " << name << "'s class" << endl; } } void Teacher::setMyCourse(Course *c) { if (myCourse && myCourse != c) { cout << name << " already has a course!" << endl; } else if (c && c->getTeacher() && c->getTeacher() != this) { cout << c->getName() << " already has a teacher!" << endl; } else if ((c && c->getTeacher() == this) || myCourse == c) { cout << name << " already teaches " << c->getName() << endl; } else { myCourse = c; c->teacher = this; numStudents = c->enrollmentNumber; } } void Teacher::setName(string n) { name = n; } int Teacher::getNumStudents(void) { return numStudents; } Course *Teacher::getMyCourse(void) { return myCourse; } string Teacher::getName(void) { return name; } void Teacher::printTeacher(void) { cout << "Teacher " << name << " has:" << endl; cout << getNumStudents() << " students" << endl; if (myCourse) cout << "teaches a course named " << myCourse->getName() << endl; else cout << "does not teach a course" << endl; cout << "and has favorite students named:"; for (int i = 0; i < Teacher::MAX_FAVORITES; i++) { if (myFavorites[i]) cout << " " << myFavorites[i]->getName() << ","; } cout << endl << endl; }