/* * querySet() * * Read in and parse through the given file. The 'Query' file contains a list of * student ID numbers. Each entry in the Query file is a student ID given on a * line by itself. You are to compute and report the GPA for each of the students * listed in the Query file. The following is an example Query file: * * 5291738860 * 9251733870 * * For each student ID given in the Query file, use the student information stored in * your set to compute the GPA for the student and create an output string which * contains the student ID, GPA, and name. If the given student ID does not match any * student, do not give any output for that student ID. Each line of the output string * contains student ID, GPA, and name as shown: * * 5291738860 2.85 Dick B. Smith * 9251733870 3.00 Harry C. Anderson * * Return a string representation of the given query. If an invalid file name is given, * then return an empty string. The precision of the GPA will be rounded to two decimal places. * There will be a trailing new line. */ string GPA::querySet(string fileName) { ifstream file; file.open(fileName); if (file.fail() || file.bad()) { return ""; } unsigned long long int ID = 0; stringstream ss; StudentInterface* student = NULL; typedef set<StudentInterface*, Comparator>::iterator it; while (file >> ID) { it itr; for (itr = mySet.begin(); itr != mySet.end(); itr++) { if ((*itr)->getID() == ID) { student = *itr; ss << ID << " " << student->getGPA() << " " << student->getName() << "\n"; } } } file.close(); return ss.str(); }
string GPA::queryMap(string fileName) { if(!checkQueryFile(fileName)) { string empty = ""; return empty; } stringstream sout; ifstream queryfile; queryfile.open(fileName.c_str()); string idin; cout << fileName << endl; while(getline(queryfile, idin)) { //cout << "made it here " << idin << endl; stringstream ss; unsigned long long int id; ss << idin; ss >> id; if (mapFindStudent(id) != NULL) { StudentInterface* student = new Student(); delete student; student = mapFindStudent(id); sout << student->getID() << " " << student->getGPA() << " " << student->getName() << "\n"; } } queryfile.close(); return sout.str(); }