1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
|
#ifndef WRAPPER_H
#define WRAPPER_H
#include <iostream>
#include <list>
using namespace std;
class Course
class Student
{
typedef list<Course *>::iterator citerator;
public:
Student (string n): nameText(n) { }
string getWaitList() {return waitlist;}
//operations
string name() {return nameText;}
void addCourse(Course * c) {courses.push_back(c);}
citerator firstCourse() {return courses.begin();}
citerator lastCourse() {return courses.end();}
void removeCourse (citerator & citer) {courses.erase(citer);}
private:
string waitlist;
string nameText;
list <Course * > courses;
//friend class Wrapper
};
class Student
class Course
{
friend class Wrapper;
public:
Course(string n, int s, string p, string c):name(n), max(s),
professor(p), classroom(c) { }
Course(string n, int s):name(n), max(s) { }
string getName() {return name;}
string getProfessor() {return professor;}
string getClassroom() {return classroom;}
bool full() {return Student.size()>=max;}
void addStudent (Student * s) {students.push_back(s);}
void generateClassList();
private:
string professor;
string classroom;
string name;
int max;
list <Student *> students;
};
class Wrapper
{
public:
Wrapper();
Wrapper(list <Course *> course, list <Student *> student);
void readStudents(istream & infile);
void fillCourses();
Student * findStudent (string & searchName);
Course * findCourse (string & searchName);
string getwname() { return wname; };
void readCourses(istream & infile);
void generateCourseReports();
void generateStudentReports();
protected:
string wname;
string professor;
string classroom;
list <Student *> all_students;
list <Course *> all_courses;
};
Wrapper::Wrapper()
{
all_students;
all_courses;
}
void Wrapper::readCourses(istream & infile)
{
string name;
int max;
string professor;
string classroom;
while (infile >> name >> max >> professor >> classroom)
{
Course * newCourse = new Course (name, max, professor, classroom);
all_courses.push_back(newCourse);
}
}
void Wrapper::readStudents(istream & infile)
{
string name;
string course;
while (infile >> name >> course)
{
Student * theStudent = findStudent(name);
Course * theCourse = findCourse(course);
if (theCourse != 0)
{
theStudent -> addCourse(theCourse);
}
else
cout << "student " << name << " requested invalid course " <<
course << endl;
}
}
void Wrapper::fillCourses()
{
list<Student *>::iterator s_start, s_end;
s_start = all_students.begin();
s_end = all_students.end();
for ( ; s_start != s_end; ++s_start)
{
list<Course *>::iterator c_start, c_end, c_next;
c_start = (*s_start) -> firstCourse();
c_end = (*s_start) -> lastCourse();
for ( ; c_start != c_end; c_start = c_next)
{
c_next = c_start; ++c_next;
if (!(*c_start) -> full())
(*c_start) -> addStudent(*s_start);
else
(*s_start) -> removeCourse(c_start);
}
}
}
Student * Wrapper::findStudent (string & searchName)
{
list <Student *>::iterator start, stop;
start = all_students.begin();
stop = all_students.end();
for ( ; start != stop; ++start)
{
if ((*start) -> name() == searchName)
return *start;
}
//if not found, make one
Student * newStudent = new Student(searchName);
all_students.push_back(newStudent);
return newStudent;
}
Course * Wrapper::findCourse (string & searchName)
{
list <Course *>::iterator start, stop;
start = all_courses.begin();
stop = all_courses.end();
for ( ; start != stop; ++start)
{
if ((*start) -> getname() == searchName)
return *start;
}
//if not found, make one
Course * newCourse = new Course(searchName, NULL);
return newCourse;
}
void Wrapper::generateCourseReports()
{
list <Course *>::iterator start, stop;
start = all_courses.begin();
stop = all_courses.end();
for ( ; start != stop; ++start)
(*start) -> generateClassList();
}
void Wrapper::generateStudentReports()
{
list <Student *>::iterator s_start, s_stop;
list <Course *>::iterator c_start, c_stop;
s_start = all_students.begin();
s_stop = all_students.end();
for ( ; s_start != s_stop; ++s_start)
{
cout << endl;
cout << "Class list for " << (*s_start)->name() << ":" << endl << endl;
c_start = (*s_start) -> firstCourse();
c_stop = (*s_start) -> lastCourse();
for ( ; c_start != c_stop; ++c_start)
cout << (*c_start) -> getname() << " with professor " <<
(*c_start) -> getprofessor() << endl;
}
}
#endif
|