Question: Code in c++. The classes are just the filename that the students are in for example i've named the files classname.txt and classname2.txt. Right now

Code in c++. The classes are just the filename that the students are in for example i've named the files classname.txt and classname2.txt. Right now the code simply lists out the students under each class not with the class attacked to the student. Recode the roster example we studied in class such that it prints the list of classes each student is enrolled in. Here is an example printout:

All Students last name, first name: courses enrolled Kathleen Anderson: CS1 CS3 CS4 Gerald Edwards: CS1 CS2 CS3 Mary Price: CS1 ... 

The project should be done using associative containers and class Student to hold the name of the student. Specifically, you need to use a map keyed by the class Student while value could be a list of classes the student is enrolled in. The map should be the ordered map. That is, the data structure to be used in as follows: map>

#include #include #include #include #include #include using std::ifstream; using std::string; using std::getline; using std::list; using std::vector; using std::cout; using std::endl; using std::move; class Student{ public: Student(string firstName, string lastName): firstName_(firstName), lastName_(lastName) {} // move constructor, not really needed, generated automatically Student(Student && org): firstName_(move(org.firstName_)), lastName_(move(org.lastName_)) {} // force generation of default copy constructor Student(const Student & org) = default; string print() const {return firstName_ + ' ' + lastName_;} // needed for unique() and for remove() friend bool operator== (Student left, Student right){ return left.lastName_ == right.lastName_ && left.firstName_ == right.firstName_; } // needed for sort() friend bool operator< (Student left, Student right){ return left.lastName_ < right.lastName_ || (left.lastName_ == right.lastName_ && left.firstName_ < right.firstName_); } private: string firstName_; string lastName_; }; // reading a list from a fileName void readRoster(list& roster, string fileName); // printing a list out void printRoster(const list& roster); int main(int argc, char* argv[]){ if (argc <= 1){ cout << "usage: " << argv[0] << " list of courses, dropouts last" << endl; exit(1);} // vector of courses of students vector > courseStudents; for(int i=1; i < argc-1; ++i){ list roster; readRoster(roster, argv[i]); cout << " " << argv[i] << " "; printRoster(roster); courseStudents.push_back(move(roster)); } // reading in dropouts list dropouts; readRoster(dropouts, argv[argc-1]); cout << " dropouts "; printRoster(dropouts); list allStudents; // master list of students for(auto& lst : courseStudents) allStudents.splice(allStudents.end(),lst); cout << " all students unsorted "; printRoster(allStudents); allStudents.sort(); // sorting master list cout << " all students sorted "; printRoster(allStudents); allStudents.unique(); // eliminating duplicates cout << " all students, duplicates removed "; printRoster(allStudents); for (const auto& str : dropouts) // removing individual dropouts allStudents.remove(str); cout << " all students, dropouts removed "; printRoster(allStudents); } void readRoster(list& roster, string fileName){ ifstream course(fileName); string first, last; while(course >> first >> last) roster.push_back(Student(first, last)); course.close(); } // printing a list out void printRoster(const list& roster){ for(const auto& student : roster) cout << student.print() << endl; }

Classname.txt

Mary Price Stephanie Watson Rachel Rivera Raymond Powell Catherine Ward Doris Howard Cynthia Jenkins Betty Torres Juan Cox Kathleen Anderson Mark Russell Gerald Edwards Mikhail Nesterenko Charles Martin Linda Johnson David Collins Elizabeth Jones Jonathan Baker Maria Kelly Martin Taylor Dennis White Brian Sanchez

classname2.txt

Joyce Rodriguez Sharon Bennett John Jenkins Gerald Edwards Rachel Peterson Marilyn Phillips Catherine Morgan Lori Walker Julie Perry Peter Young Peter Hall Mark Russell Linda Johnson Dennis White

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!