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 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
#include <iostream>
#include <string>
#include <iomanip>
#include <fstream>
using namespace std;
#define row 10
#define col 6
ifstream inputname, inputgrade;
struct studentRecord
{
string name;
int grade;
int sum;
double average;
char letter;
};
void readStudentData(studentRecord n[row], studentRecord g[row][col])
{
inputname.open("name.txt");
inputgrade.open("grade.txt");
for (int r = 0; r < row; r++)
{
getline(inputname, n[r].name);
for (int i = 0; i < col; i++)
{
inputgrade >> g[r][i].grade;
}
}
}
void printStudentData1(studentRecord n[row], studentRecord g[row][col])
{
for (int r = 0; r < row; r++)
{
cout << n[r].name << endl;
for (int i = 0; i < col; i++)
{
cout << g[r][i].grade << " " << "\t";
}
cout << endl;
}
cout << endl;
}
void sumOfGrade(studentRecord g[row][col], studentRecord s[row])
{
for (int r = 0; r < row; r++)
{
for (int i = 0; i < col; i++)
{
s[r].sum += g[r][i].grade;
}
}
}
void averageGrade(studentRecord s[row], studentRecord a[row])
{
for (int r = 0; r < row; r++)
{
a[r].average = s[r].sum / col;
}
}
void letterGrade(studentRecord a[row], studentRecord l[row])
{
for (int r = 0; r < row; r++)
{
if (a[r].average >= 90)
{
l[r].letter = 'A';
}
if (a[r].average >= 80)
{
l[r].letter = 'B';
}
if (a[r].average >= 70)
{
l[r].letter = 'C';
}
if (a[r].average >= 60)
{
l[r].letter = 'D';
}
}
}
void printStudentData2(studentRecord n[row], studentRecord g[row][col], studentRecord s[row], studentRecord a[row], studentRecord l[row])
{
for (int r = 0; r < row; r++)
{
cout << n[r].name << endl;
cout << "Total: " << s[r].sum << endl;
cout << "Average: " << a[r].average << endl;
cout << "Letter Grade: " << l[r].letter << endl;
for (int i = 0; i < col; i++)
{
cout << g[r][i].grade << "\t";
cout << endl;
}
cout << endl;
}
}
void main()
{
studentRecord name[row];
studentRecord grade[row][col];
studentRecord sum[row];
studentRecord average[row];
studentRecord letter[row];
readStudentData(name, grade);
printStudentData1(name, grade);
sumOfGrade(grade, sum);
averageGrade(sum, average);
letterGrade(average, letter);
printStudentData2(name, grade, sum, average, letter);
inputname.close();
inputgrade.close();
system("pause");
}
|