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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121
|
#include <iostream>
#include <fstream>
using namespace std;
void initialize(ifstream &, string, int[]);
double calcAverage(int);
char determineGrade (double);
void printStudent (string, double, char);
void countGrade (char);
int count = 0;
int main()
{
cout << "Student, Grade, and Average Calculator" << endl;
cout << endl;
ifstream inputfile;
inputfile.open("input.txt");
string name; int grades[5];
inputfile >> name;
while (inputfile)
{
initialize(inputfile, name, grades);
count++;
}
if(inputfile.fail())
{
cout<<"Input file invalid.";
return 1;
}
inputfile>> name;
cout << "Total Number of Students: " << count << endl;
inputfile.close();
return 0;
}
void initialize(ifstream &in, string name, int y)
{
double average; char grade;
average = calcAverage(y);
grade = determineGrade(average);
printStudent(name, average, grade);
}
double calcAverage(int y)
{
double average; int sum = 0;
sum += y;
average = sum / 5;
return average;
}
char determineGrade(double average)
{
char A, B, C, D, F;
if(average >= 90)
{
return 'A';
countGrade(A);
}
else if(average >=80)
{
return 'B';
countGrade(B);
}
else if(average >=70)
{
return 'C';
countGrade(C);
}
else if(average>=60)
{
return 'D';
countGrade(D);
}
else
{
return 'F';
countGrade(F);
}
}
void printStudent (string name, double average, char grade)
{
cout << "Name: " << name << "Average grade is: " << average << "Final Grade: " << grade << endl;
}
void countGrade(char x)
{
int A = 0, B = 0, C = 0, D = 0, F = 0;
if (x = 'A')
A++;
else if (x = 'B')
B++;
else if (x = 'C')
C++;
else if (x = 'D')
D++;
else if (x = 'F')
F++;
cout << endl;
cout << "Total A's: " << A << endl;
cout << "Total B's: " << B << endl;
cout << "Total C's: " << C << endl;
cout << "Total D's: " << D << endl;
cout << "Total F's: " << F << endl;
}
|