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
|
#include <iostream>
#include <conio.h>
#include <fstream>
#include <iomanip>
using namespace std;
struct SStudent
{
int id;
double test[2], hw[7], hwAve, testAve, finalScore, grade;
};
int getInput(SStudent [], int);
void process(SStudent [], int);
void display(const SStudent [], int);
int main()
{
int totalStudents, i;
SStudent student[30];
totalStudents = getInput(student, 30);
process(student, totalStudents);
display(student, totalStudents);
_getch();
}
int getInput(SStudent students[], int size)
{
int i = 0;
ifstream inFile;
inFile.open("scores.txt");
if(!inFile)
{
cout << "Can't open input file\n";
_getch();
exit(1);
}
for(int i = 0; i < size; ++i)
{
inFile >> students[i].id;
for(int j = 0; j < 2; ++j)
inFile >> students[i].test[j];
for (int k = 0; k < 7; ++k)
inFile >> students[i].hw[k];
if(!inFile) break;
}
return i;
}
void process(SStudent students[], int size)
{
for(int i = 0; i < size; ++i)
{
for(int j = 0; j < 2; ++j)
students[i].testAve += students[i].test[j];
for(int k = 0; k < 7; ++k)
students[i].hwAve += students[i].hw[k];
students[i].hwAve = students[i].hwAve / 265;
students[i].testAve = students[i].testAve / 200;
students[i].finalScore = (students[i].hwAve * 0.40) + (students[i].testAve * 0.60) * 100;
if (students[i].finalScore < 60)
students[i].grade = 'E';
else if (students[i].finalScore > 60 && students[i].grade <= 69)
students[i].grade = 'D';
else if (students[i].finalScore > 69 && students[i].grade <= 79)
students[i].grade = 'C';
else if (students[i].finalScore > 79 && students[i].grade <= 89)
students[i].grade = 'B';
else
students[i].grade = 'A';
}
}
void display(const SStudent students[], int size)
{
ofstream outFile;
outFile.open("grades.txt");
outFile << fixed << showpoint;
outFile << setprecision(1);
outFile << "STUDENT ID\tHW AVE\t\tTEST AVE\tFINAL SCORE\tGRADE" << endl;
for(int i = 0; i < size; ++i)
cout << students[i].id << "\t" << students[i].hwAve << "\t\t" << students[i].testAve << "\t\t" << students[i].finalScore << "\t\t" << students[i].grade << endl;
cout << "Output file created.";
}
|