summaryrefslogtreecommitdiff
path: root/Q3.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'Q3.cpp')
-rw-r--r--Q3.cpp182
1 files changed, 182 insertions, 0 deletions
diff --git a/Q3.cpp b/Q3.cpp
new file mode 100644
index 0000000..75e4213
--- /dev/null
+++ b/Q3.cpp
@@ -0,0 +1,182 @@
+
+#include <iostream>
+
+#include "Student.h"
+#include "Teacher.h"
+#include "Course.h"
+
+using namespace std;
+
+int main(int argc, const char *argv[])
+{
+ Student **students = new Student*[100];
+ const char *letters = "0123456789";
+
+ // make 100 students with rather generic names
+ for (int i = 0; i < 10; i++) {
+ for (int j = 0; j < 10; j++) {
+ char *name = new char[3];
+ name[0] = letters[i];
+ name[1] = letters[j];
+ name[2] = '\0';
+ students[10*i+j] = new Student(name);
+ }
+ }
+
+ // make a few courses
+ cout << "making courses" << endl;
+ Course *c1 = new Course(); // default
+ Course *c2 = new Course("english", 50);
+ Course *c3 = new Course("math", 10);
+
+ // make a few teachers
+ cout << "making teachers" << endl;
+ Teacher *t1 = new Teacher();
+ Teacher *t2 = new Teacher("john");
+ Teacher *t3 = new Teacher("steve");
+
+ cout << "teachers:" << endl;
+ t1->printTeacher();
+ t2->printTeacher();
+ t3->printTeacher();
+
+ cout << endl;
+ // mutator
+ t1->setName("barbara");
+ cout << "changed t1:" << endl;
+ t1->printTeacher();
+
+ cout << "courses:" << endl;
+ c1->printCourse();
+ c2->printCourse();
+ c3->printCourse();
+
+ // test mutator
+ c1->setName("comp sci");
+ cout << "changed c1" << endl;
+ c1->printCourse();
+
+ cout << endl;
+
+ cout << "assigning teachers to classes" << endl;
+ c1->addTeacher(t1);
+ t2->setMyCourse(c2);
+ c3->addTeacher(t3);
+
+ // reprint
+ cout << "classes: " << endl;
+ c1->printCourse();
+ c2->printCourse();
+ c3->printCourse();
+
+ // reprint
+ cout << "teachers: " << endl;
+ t1->printTeacher();
+ t2->printTeacher();
+ t3->printTeacher();
+
+
+ // overassign
+ cout << "test assigning more than 1 teacher to a class" << endl;
+ t3->setMyCourse(c1);
+ c3->addTeacher(t1);
+
+ cout << endl;
+
+ cout << "adding students to classes" << endl;
+ // c1
+ cout << "c1" << endl;
+ for (int i = 0; i < 100; i++) {
+ c1->addStudent(students[i]);
+ }
+
+ // c2, but overassigned
+ cout << "c2, overassigned" << endl;
+ for (int i = 0; i < 52; i++) {
+ c2->addStudent(students[i]);
+ }
+
+ // c3
+ cout << "c3" << endl;
+ for (int i = 0; i < 10; i++) {
+ c3->addStudent(students[i]);
+ }
+ // double assign
+ cout << "assign same student to same class" << endl;
+ c3->addStudent(students[0]);
+ c3->addStudent(students[5]);
+
+ // reprint
+ cout << "courses: " << endl;
+ c1->printCourse(); // too long
+ c2->printCourse();
+ c3->printCourse();
+
+ // deleting
+ cout << "test deleting students" << endl;
+ c3->removeStudent(students[3]);
+ c3->removeStudent(students[8]);
+ c3->removeStudent(students[11]);
+
+ // adding new
+ cout << "and re-adding them" << endl;
+ c3->addStudent(students[39]);
+ c3->addStudent(students[33]);
+
+ // favorites
+ cout << endl;
+ cout << "test setting favorites" << endl;
+
+ cout << "t1" << endl;
+ for (int i = 0; i < 7; i++) {
+ t1->addToMyFavorites(students[i]);
+ }
+
+ cout << "t2" << endl;
+ for (int i = 0; i < 10; i++) {
+ t2->addToMyFavorites(students[i]);
+ }
+ // too many
+ cout << "too many favorites" << endl;
+ t2->addToMyFavorites(students[13]);
+ t2->addToMyFavorites(students[32]);
+
+ cout << "t3" << endl;
+ for (int i = 0; i < 8; i++) {
+ t3->addToMyFavorites(students[i]);
+ }
+ // not in class
+ cout << "add favorites not in clas" << endl;
+ t3->addToMyFavorites(students[31]);
+ t3->addToMyFavorites(students[92]);
+
+ // reprint
+ cout << "teachers: " << endl;
+ t1->printTeacher();
+ t2->printTeacher();
+ t3->printTeacher();
+
+ // remove a favorite
+ cout << "test removing a favorite student from a class" << endl;
+ cout << "(should also remove it from a teacher's favorites)" << endl;
+ c2->removeStudent(students[6]);
+ t2->printTeacher();
+
+ cout << endl;
+
+ // removing teachers
+ cout << "test removing teachers" << endl;
+ c2->removeTeacher();
+ c2->printCourse();
+ t2->printTeacher();
+
+ // replace it
+ cout << "replace removed with a different one" << endl;
+ Teacher *t4 = new Teacher("greg");
+ c2->addTeacher(t4);
+ c2->printCourse();
+ t4->printTeacher();
+
+
+ return 0;
+}