riggnaros

Grading Calc Revised

Oct 25th, 2017
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <limits>
  4. #include <cmath>
  5. #include <iomanip>
  6. #include <fstream>
  7.  
  8. using namespace std;
  9.  
  10. void gradeCalc(int studentID, int count, double midterm, double finalExam, double researchPaper, double groupProject, double participation, double studentAvg, double& overallAvg, double gradeSum, char letterGrade);
  11. void printGrade(int studentID, int count, double midterm, double finalExam, double researchPaper, double groupProject, double participation, double studentAvg, double& overallAvg, char letterGrade);
  12.  
  13. int main()
  14. {
  15.     int studentID;
  16.     int count = 0;
  17.  
  18.     double midterm;
  19.     double finalExam;
  20.     double researchPaper;
  21.     double groupProject;
  22.     double participation;
  23.     double studentAvg;
  24.     double overallAvg;
  25.     double gradeSum;
  26.     char letterGrade;
  27.  
  28.     gradeCalc(studentID, count, midterm, finalExam, researchPaper, groupProject, participation, studentAvg, overallAvg, gradeSum, letterGrade);
  29.     printGrade(studentID, count, midterm, finalExam, researchPaper, groupProject, participation, studentAvg, overallAvg, letterGrade);
  30.  
  31.     return 0;
  32. }
  33.  
  34. void printGrade(int studentID, int count, double midterm, double finalExam, double researchPaper, double groupProject, double participation, double studentAvg, double& overallAvg, char letterGrade)
  35. {
  36.  
  37.     ifstream infile;
  38.     ofstream outfile;
  39.  
  40.     infile.open("grades.dat");
  41.     outfile.open("grades.txt");
  42.     outfile << "STUDENT GRADING REPORT: ";
  43.     outfile << fixed << showpoint << setprecision(2);
  44.  
  45.     while (!infile.eof()) {
  46.  
  47.         infile >> studentID >> midterm >> finalExam >> researchPaper >> groupProject >> participation;
  48.  
  49.         if (studentID > 1 && studentID <= 999) {
  50.             count++;
  51.  
  52.             outfile << endl
  53.                     << "Student ID: " << studentID << ' ' << "Midterm: " << midterm << ' ' << "Final Exam: " << finalExam << ' ' << "Research Paper: " << researchPaper << ' ' << "Group Project: " << groupProject
  54.                     << "Participation: " << participation << ' ' << "Student Average: " << studentAvg << ' ' << "Letter Grade: " << letterGrade;
  55.         }
  56.     }
  57.     outfile << endl
  58.             << "Total # of Students: " << count << ' ' << "Overall Class Average: " << overallAvg;
  59.  
  60.     infile.close();
  61.     outfile.close();
  62. };
  63.  
  64. void gradeCalc(int studentID, int count, double midterm, double finalExam, double researchPaper, double groupProject, double participation, double studentAvg, double& overallAvg, double gradeSum, char letterGrade)
  65. {
  66.  
  67.     //midterm = .25
  68.     //finalExam = .25
  69.     //researchPaper = .20
  70.     //groupProject = .20
  71.     //participation = .10
  72.  
  73.     ifstream infile;
  74.     ofstream outfile;
  75.  
  76.     infile.open("grades.dat");
  77.  
  78.     while (!infile.eof()) {
  79.  
  80.         infile >> studentID >> midterm >> finalExam >> researchPaper >> groupProject >> participation;
  81.         studentAvg = ((midterm * .25) + (finalExam * .25) + (researchPaper * .20) + (groupProject * .20) + (participation * .10));
  82.  
  83.         if (studentID > 1 && studentID <= 999) {
  84.             count++;
  85.             gradeSum += studentAvg;
  86.  
  87.             if (studentAvg >= 90) {
  88.                 letterGrade = 'A';
  89.             }
  90.             else if (studentAvg >= 80 && studentAvg <= 89.99) {
  91.                 letterGrade = 'B';
  92.             }
  93.             else if (studentAvg >= 70 && studentAvg <= 79.99) {
  94.                 letterGrade = 'C';
  95.             }
  96.             else if (studentAvg < 70) {
  97.                 letterGrade = 'F';
  98.             }
  99.  
  100.             cout << endl
  101.                  << fixed << showpoint << setprecision(2) << "Student ID: " << studentID << ' ' << "Average:  " << studentAvg << ' ' << "Letter Grade: " << letterGrade;
  102.         }
  103.         if (count != 0) {
  104.             overallAvg = (gradeSum / (count + 1));
  105.         }
  106.     }
  107.     cout << endl
  108.          << "Total # of Students: " << count << ' ' << "Overall Class Average: " << overallAvg;
  109.  
  110.     infile.close();
  111. };
Advertisement
Add Comment
Please, Sign In to add comment