Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. void letterB (const string &input, const College &college, const unordered_map<string, vector<Course>> &map) {
  2. double percentage;
  3. string gradingType;
  4. cout << "letter B threshold? ";
  5. cin >> percentage;
  6.  
  7. vector<Course> coursePercentages;
  8. // perform a department wide search
  9. if (!(input == "all")) {
  10.  
  11. if (map.find(input) == map.end()) {
  12. cout << "**dept not found\n";
  13. return;
  14. }
  15.  
  16. // get the courses from the department
  17. vector<Course> deptCourses = map.at(input);
  18.  
  19. // retrieve the courses in the specified department
  20. for (auto &c: deptCourses) {
  21. GradeStats stats = GetGradeDistribution(c);
  22. // if the percent of Bs are greater than the percentage entered, add to the vector
  23. if (stats.PercentB > percentage) {
  24. coursePercentages.push_back(c);
  25. }
  26. }
  27. }
  28.  
  29. // perform a college-wide search
  30. else if (input == "all") {
  31. for (auto &d: college.Depts) {
  32. for (auto &c: d.Courses) {
  33. GradeStats stats = GetGradeDistribution(c);
  34. if (stats.PercentB > percentage) {
  35. coursePercentages.push_back(c);
  36. }
  37. }
  38. }
  39. }
  40.  
  41. // sort the B percentages vector by percentB > department > course number > section number
  42. sort(coursePercentages.begin(), coursePercentages.end(), [=] (Course &a, Course &b) {
  43. GradeStats aStats = GetGradeDistribution(a);
  44. GradeStats bStats = GetGradeDistribution(b);
  45.  
  46. if ((fabs(aStats.PercentB) < fabs(bStats.PercentB) < .0001)) {
  47. return true;
  48. }
  49. else if ((fabs(aStats.PercentB) > fabs(bStats.PercentB) < .0001)) {
  50. return false;
  51. }
  52. else {
  53. if (a.Dept < b.Dept) {
  54. return true;
  55. }
  56. else if (a.Dept > b.Dept) {
  57. return false;
  58. }
  59. else {
  60. if (a.Number < b.Number) {
  61. return true;
  62. }
  63. else if (a.Number > b.Number) {
  64. return false;
  65. }
  66. else {
  67. if (a.Section < b.Section) {
  68. return true;
  69. }
  70. else {
  71. return false;
  72. }
  73. }
  74. }
  75. }
  76. });
  77.  
  78. if (coursePercentages.empty()) {
  79. cout << "**none found\n";
  80. return;
  81. }
  82.  
  83. for (auto &c: coursePercentages) {
  84. cout << c.Dept << " " << c.Number << " (section " << c.Section << "): " << c.Instructor << endl;
  85. cout << " # students: " << c.getNumStudents() << endl;
  86.  
  87.  
  88. // determine the grading type
  89. if (c.getGradingType() == 0) gradingType = "letter";
  90. else if (c.getGradingType() == 1) gradingType = "satisfactory";
  91. else if (c.getGradingType() == 2) gradingType = "unknown";
  92.  
  93. cout << " course type: " << gradingType << endl;
  94. printDistribution(GetGradeDistribution(c));
  95. printDFW(c);
  96.  
  97. }
  98. //printResults(coursePercentages);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement