summaryrefslogtreecommitdiff
path: root/Teacher.cpp
diff options
context:
space:
mode:
authorMichael Abed <michaelabed@gmail.com>2012-04-09 01:45:23 -0400
committerMichael Abed <michaelabed@gmail.com>2012-04-09 01:48:41 -0400
commit1ba0668dbcf5bc4c40d99ac963711e35797c8efa (patch)
treeb359b81f4e538e923366a7c718d9defd9b823bc4 /Teacher.cpp
downloadec327-lab3-master.tar.gz
ec327-lab3-master.tar.bz2
ec327-lab3-master.zip
finished assignmentHEADmaster
Diffstat (limited to 'Teacher.cpp')
-rw-r--r--Teacher.cpp88
1 files changed, 88 insertions, 0 deletions
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;
+}