/* * 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(); }
void main() { Address a1(9,"ness-zione","nordao"); Date d1(1,6,1990); Address a2(41,"holon","mifratz shlomo"); Date d2(3,12,1990); Address a3(9,"ness-ziona","nordao"); Date d3(24,5,1964); FirstDegree s1(201435484,"oreyan","sabah",&a1,&d1); SecondDegree s2(304816499,"shirly","ezer",&a2,&d2); NotStuding s3(58502840,"jackline","sabah",&a3,&d3); Teacher t1 (256874926,"alexnder","spivak"); Teacher t2 (365489247,"liat","nakar"); FirstDegreeCourse c1(2455,"infy 1",'a',&t1,6); t1.AddCourse(&c1); SecondDegreeCourse c2(3899,"infy 2",'b',&t1,5); t1.AddCourse(&c2); AdvancedFirstDegreeCourse c3(4566,"c++",'a',&t2,5); t2.AddCourse(&c3); AllCourses *list1=AllCourses::GetInstance(); list1->AddCourse(&c1); list1->AddCourse(&c2); list1->AddCourse(&c3); AllStudents *list2=AllStudents::GetInstance(); list2->AddStudent(&s1); list2->AddStudent(&s2); list2->AddStudent(&s3); AllTeachers *list3=AllTeachers::GetInstance(); list3->AddTeacher(&t1); list3->AddTeacher(&t2); int choose; long int id; cout <<"Are you :\n1.Student\n2.Teacher\n3.Administrative\n"; cin >> choose; system ("cls"); if( choose == 1 ) { StudentInterface S; S.DisplayInterface(); } if( choose == 2 ) { TeacherInterface T; T.DisplayInterface(); } if( choose == 3 ) { AdministrativePeopleInterface A; A.DisplayInterface(); } AllStudents *l1=AllStudents::GetInstance(); AllCourses *l2=AllCourses::GetInstance(); l1->DisplayAll(); l2->DisplayAll(); getchar(); }
StudentInterface* GPA::setFindStudent(unsigned long long int ID) { for(set<StudentInterface*, Comparator>::iterator curr = gpaset.begin(); curr != gpaset.end(); curr++) { StudentInterface* student = *curr; if (student->getID() == ID) { return student; } } return NULL; }
bool GPA::importGrades(string fileName) { if (!checkGradeFile(fileName)) { //cout << "One file bad: " << fileName << endl; return false; } ifstream gradesIn; gradesIn.open(fileName.c_str()); string id; while(getline(gradesIn, id)) { unsigned long long int idin; stringstream ss; ss << id; ss >> idin; string className; string letterGrade; getline(gradesIn, className); getline(gradesIn, letterGrade); double GPA = findGPA(letterGrade); if (mapFindStudent(idin) != NULL) { StudentInterface* mapStudent = new Student(); delete mapStudent; mapStudent = mapFindStudent(idin); mapStudent->addGPA(GPA); } else if (setFindStudent(idin) != NULL) { //cout << "HERE: " << GPA << endl; StudentInterface* setStudent = new Student(); delete setStudent; setStudent = setFindStudent(idin); setStudent->addGPA(GPA); } } gradesIn.close(); return true; }
/* * importGrades() * * Read in and parse through the given file. Each part of an entry in the file * is given on a separate line in the file. Student ID is first, course is * second, and grade is last. There are no blank lines between entries. The * following is an example file: * * 5291738860 * CHEM134 * A * 9251734870 * BOT180 * B * 9251733870 * PE273 * D+ * 5291738760 * HIS431 * A- * * Compute the GPA by finding the average of all the grades with a matching student ID * in the Grade file. The GPA is calculated by taking a Student's total sum GPA and * dividing by the number of classes taken. If the given student ID has no matching * grades in the Grade file, the GPA is 0.00. It is not necessary to store the course * names so long as the total number of courses taken is counted. * * You may assume that the given student ID exists in the map or set. * * Use the following point values for each grade. * * A = 4.0 A- = 3.7 * B+ = 3.4 B = 3.0 B- = 2.7 * C+ = 2.4 C = 2.0 C- = 1.7 * D+ = 1.4 D = 1.0 D- = 0.7 * E = 0.0 * * Returns false if an invalid filename is given, otherwise true. */ bool GPA::importGrades(string fileName) { string student_id; string course_name; string grade; StudentInterface* student = NULL; ifstream file; file.open(fileName); if (!isValidClass(fileName)) { file.close(); return false; } typedef set<StudentInterface*, Comparator>::iterator it; while (getline(file, student_id)) { unsigned long long int ID = atoi(student_id.c_str()); getline(file, course_name); getline(file, grade); // grabbed each line, now need to check if the student_id is equal to any in the set and map // if it is, add that to the gpa and add to num classes // either in set or map if (myMap[ID] == NULL) // not in map, it is in set { myMap.erase(ID); it itr; for (itr = mySet.begin(); itr != mySet.end(); itr++) { if ((*itr)->getID() == ID) { student = *itr; } } } else { student = myMap[ID]; } if (grade == "A") { student->addGPA(4.0); } else if (grade == "A-") { student->addGPA(3.7); } else if (grade == "B+") { student->addGPA(3.4); } else if (grade == "B") { student->addGPA(3.0); } else if (grade == "B-") { student->addGPA(2.7); } else if (grade == "C+") { student->addGPA(2.4); } else if (grade == "C") { student->addGPA(2.0); } else if (grade == "C-") { student->addGPA(1.7); } else if (grade == "D+") { student->addGPA(1.4); } else if (grade == "D") { student->addGPA(1.0); } else if (grade == "D-") { student->addGPA(0.7); } else if (grade == "E") { student->addGPA(0.0); } } file.close(); return true; }