From 1ba0668dbcf5bc4c40d99ac963711e35797c8efa Mon Sep 17 00:00:00 2001 From: Michael Abed Date: Mon, 9 Apr 2012 01:45:23 -0400 Subject: finished assignment --- Teacher.cpp | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 Teacher.cpp (limited to 'Teacher.cpp') diff --git a/Teacher.cpp b/Teacher.cpp new file mode 100644 index 0000000..ab08119 --- /dev/null +++ b/Teacher.cpp @@ -0,0 +1,88 @@ + +#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; +} -- cgit v1.2.3