Question: I have an error with my code, #include #include #include #include #include using namespace std; struct StudentData { int studentID; string first_name; string last_name; int
I have an error with my code,
#include
using namespace std;
struct StudentData { int studentID; string first_name; string last_name; int exam1; int exam2; int exam3; int total; char ch; };
const int SIZE = 9; const int INFO = 4;
void openInputFile(ifstream &, string); void getTotal(StudentData[]); void getGrade(StudentData[]); void calcLowest(StudentData[], int &, int &, int &, int &, int[]); void calcHighest(StudentData[], int &, int &, int &, int &, int[]); void getAverage(StudentData[], int, double &, double &, double &, double &, double[]); void getStd(StudentData[], double &, double &, double &, double &, double &, double &, double &, double &, double[]); void print(StudentData[], int[], int[], double[], double[]); void sort(StudentData[]);
int main() {
StudentData arr[SIZE]; int lowest1, lowest2, lowest3, lowest4; int highest1, highest2, highest3, highest4; double average1 = 0, average2 = 0, average3 = 0, average4 = 0; double std1 = 0, std2 = 0, std3 = 0, std4 = 0; int lowest[INFO] = {}; int highest[INFO] = {}; double average[INFO] = {}; double standardDeviation[INFO] = {};
ifstream inFile; string inFileName = "students.txt";
openInputFile(inFile, inFileName);
for (int count = 0; count > arr[count].studentID >> arr[count].first_name >> arr[count].last_name >> arr[count].exam1 >> arr[count].exam2 >> arr[count].exam3; }
inFile.close();
getTotal(arr);
getGrade(arr);
calcLowest(arr, lowest1, lowest2, lowest3, lowest4, lowest);
calcHighest(arr, highest1, highest2, highest3, highest4, highest);
getAverage(arr, SIZE, average1, average2, average3, average4, average);
getStd(arr, std1, std2, std3, std4, average1, average2, average3, average4, standardDeviation);
cout
print(arr, lowest, highest, average, standardDeviation);
cout
sort(arr);
print(arr, lowest, highest, average, standardDeviation);
system("PAUSE");
return 0; }
void openInputFile(ifstream &inFile, string inFileName) {
inFile.open(inFileName);
if (!inFile) { cout
void getTotal(StudentData arr[]) { for (int i = 0; i
void getGrade(StudentData arr[]) { for (int i = 0; i = 270) arr[i].ch = 'A'; else if (arr[i].total >= 240) arr[i].ch = 'B'; else if (arr[i].total >= 210) arr[i].ch = 'C'; else if (arr[i].total >= 180) arr[i].ch = 'D'; else arr[i].ch = 'F'; } }
void calcLowest(StudentData arr[], int &lowest1, int &lowest2, int &lowest3, int &lowest4, int lowest[]) { int smallest = 0;
lowest1 = arr[0].exam1; lowest2 = arr[0].exam2; lowest3 = arr[0].exam3; lowest4 = arr[0].total;
for (int i = 0; i arr[i].exam1) { lowest1 = arr[i].exam1; smallest = i; }
if (lowest2 > arr[i].exam2) { lowest2 = arr[i].exam2; smallest = i; }
if (lowest3 > arr[i].exam3) { lowest3 = arr[i].exam3; smallest = i; }
if (lowest4 > arr[i].total) { lowest4 = arr[i].total; smallest = i; } }
for (int index = 0; index
void calcHighest(StudentData arr[], int &highest1, int &highest2, int &highest3, int &highest4, int highest[]) { int biggest = 0;
highest1 = arr[0].exam1; highest2 = arr[0].exam2; highest3 = arr[0].exam3; highest4 = arr[0].total;
for (int i = 0; i
if (highest2
if (highest3
if (highest4
// Loop highest values into an array of size 4 for (int index = 0; index
void getAverage(StudentData arr[], int size, double &average1, double &average2, double &average3, double &average4, double average[]) { int sum1 = 0, sum2 = 0, sum3 = 0, sum4 = 0;
for (int i = 0; i
// Calculate average for each category average1 += static_cast
average2 += static_cast
average3 += static_cast
average4 += static_cast
for (int index = 0; index
void getStd(StudentData arr[], double &std1, double &std2, double &std3, double &std4, double &average1, double &average2, double &average3, double &average4, double standardDeviation[]) { double deviationSum1 = 0, deviationSum2 = 0, deviationSum3 = 0, deviationSum4 = 0;
for (int i = 0; i
std1 = sqrt(deviationSum1 / ((SIZE)-1)); std2 = sqrt(deviationSum2 / ((SIZE)-1)); std3 = sqrt(deviationSum3 / ((SIZE)-1)); std4 = sqrt(deviationSum4 / ((SIZE)-1));
// Loop average values into an array of size for (int index = 0; index
cout
void print(StudentData[], int[], int[], double[], double[]) { }
void sort(StudentData arr[]) { StudentData temp;
for (int i = 0; i arr[j].last_name) { temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } }
This is the output:

This is the students.txt file:
10 878 Adams, Jerry A C D C A 50.0 100.0 A 44 Ball, Lee A B D C A 40.0 80.0 B 666 Dunn, Bob A B D C A 40.0 80.0 B 88 Hall, Bill A C D A B 30.0 60.0 D 55 Hill, Nathan A C B A B 20.0 40.0 F 111 Jones, Paul A C D C A 50.0 100.0 A 333 Land, Chris C D B C A 20.0 40.0 F 998 Miles, Sue A C D B B 30.0 60.0 D 66 Rowe, Steve A C D C A 50.0 100.0 A 22 Smith, Mary A C D B A 40.0 80.0 B
ica. C:\Wi ndows Press any key to continue Press any key to continue
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
