1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
float averageQuizzes(int, int, int , int );
float averageFinal(int, int, float);
char getLetterGrade(char);
void ifPassedClass(int, int );
int main(int argc, char *argv[]) {
string firstname,lastname;
char grade;
int quiz1,quiz2,quiz3,quiz4,midterm,final,attendance;
double quiz_average,final_average;
fstream myfile;
myfile.open("C:/Users/------/Downloads/bettergrades.txt");
while(!myfile.eof()) {
myfile >> firstname >> lastname >> quiz1 >> quiz2 >> quiz3 >> quiz4 >> midterm >> final >> attendance;
quiz_average = averageQuizzes(quiz1,quiz2,quiz3,quiz4);
final_average = averageFinal(midterm,final,quiz_average);
grade = getLetterGrade(final_average);
cout << lastname << ", " << firstname << "\t" << setprecision(0) << fixed << final_average << "\t" << grade << "\t";
ifPassedClass(final_average,attendance);
cout << endl;
}
myfile.close();
return 0;
}
// this function gets four assignment grades and averages them
float averageQuizzes(int quiz1, int quiz2, int quiz3, int quiz4) {
return (quiz1+quiz2+quiz3+quiz4)/4;
}
// this function gets a midterm, a final and the assignment average and averages them
float averageFinal(int final, int midterm, float quiz_average) {
return (quiz_average+midterm+final)/3.0;
}
// this functions takes the final average and returns the correspondingletter grade
char getLetterGrade(int final_average) {
char grade;
if (final_average >= 90) grade = 'A';
else if ((final_average < 90) && (final_average >= 80)) grade = 'B';
else if ((final_average < 80) && (final_average >= 60)) grade = 'C';
else if ((final_average < 60) && (final_average >= 50)) grade = 'D';
else grade = 'F';
}
// this function takes the final average and the number of classes attended to determine if the student passes
void ifPassedClass(int final_average, int attendance) {
if ((final_average < 60 || (attendance < 30))) cout << "Failed";
else cout << "Passed";
}
|