#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;
list
getTotalEnrollment(const vector >& classLists,const list& droppedStudents)
{
list allStudents;
for (size_t i = 0; i < classLists.size(); ++i) {
allStudents.insert(allStudents.end(), classLists[i].begin(),classLists[i].end());
}
allStudents.sort();
allStudents.unique();
for (list::const_iterator it = droppedStudents.begin();
it != droppedStudents.end(); ++it) {
allStudents.remove(*it);
}
return (allStudents);
}
void readStudentList(list &students, ifstream &istr)
{
string name;
while (getline(istr, name)) {
cout << "Read name " << name << endl;
students.push_back(name);
}
}
void readCourseLists(vector > &lists){
for(int i = 1; ; i++) {
ostringstream ostr;
ostr << "course" << i << ".txt";
ifstream istr(ostr.str().c_str());
if (!istr) {
cout << "Failed to open " << ostr.str() << endl;
break;
}
list newList;
readStudentList(newList, istr);
lists.push_back(newList);
}
}
void readDroppedStudents(list &students){
ifstream istr("dropped.txt");
readStudentList(students, istr);
}
int main(int argc, char **argv)
{
vector > courseLists;
list droppedStudents;
readCourseLists(courseLists);
readDroppedStudents(droppedStudents);
list finalList = getTotalEnrollment(courseLists, droppedStudents);
copy(finalList.begin(), finalList.end(), ostream_iterator(cout, "\n"));
}