Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need help defining the print function to get output Here is my code so far. #include #include #include #include #include using namespace std; struct

I need help defining the "print" function to get output

image text in transcribed

image text in transcribed

Here is my code so far.

#include

#include

#include

#include

#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; // Holds standard deviation for Exams 1-3 and Total

int lowest[INFO] = {};

int highest[INFO] = {};

double average[INFO] = {};

double standardDeviation[INFO] = {};

ifstream inFile;

string inFileName = "grades.dat";

openInputFile(inFile, inFileName);

for (int count = 0; count

{

inFile >> 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);

return 0;

}

void openInputFile(ifstream &inFile, string inFileName)

{

inFile.open(inFileName);

if (!inFile)

{

cout

cout

return;

}

}

void getTotal(StudentData arr[])

{

for (int i = 0; i

{

arr[i].total = arr[i].exam1 + arr[i].exam2 + arr[i].exam3;

}

}

void getGrade(StudentData arr[])

{

for (int i = 0; i

{

if (arr[i].total >= 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

{

if (lowest1 > 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

{

if (index == 0)

lowest[0] = lowest1;

else if (index == 1)

lowest[1] = lowest2;

else if (index == 2)

lowest[2] = lowest3;

else if (index == 3)

lowest[3] = lowest4;

else

cout

}

}

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 (highest1

{

highest1 = arr[i].exam1;

biggest = i;

}

if (highest2

{

highest2 = arr[i].exam2;

biggest = i;

}

if (highest3

{

highest3 = arr[i].exam3;

biggest = i;

}

if (highest4

{

highest4 = arr[i].total;

biggest = i;

}

}

for (int index = 0; index

{

if (index == 0)

highest[0] = highest1;

else if (index == 1)

highest[1] = highest2;

else if (index == 2)

highest[2] = highest3;

else if (index == 3)

highest[3] = highest4;

else

cout

}

}

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

{

sum1 += arr[i].exam1;

sum2 += arr[i].exam2;

sum3 += arr[i].exam3;

sum4 += arr[i].total;

}

average1 += static_cast(sum1) / size;

average2 += static_cast(sum2) / size;

average3 += static_cast(sum3) / size;

average4 += static_cast(sum4) / size;

for (int index = 0; index

{

if (index == 0)

average[0] = average1;

else if (index == 1)

average[1] = average2;

else if (index == 2)

average[2] = average3;

else if (index == 3)

average[3] = average4;

else

cout

}

}

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

{

deviationSum1 += pow((arr[i].exam1 - average1), 2);

deviationSum2 += pow((arr[i].exam2 - average2), 2);

deviationSum3 += pow((arr[i].exam3 - average3), 2);

deviationSum4 += pow((arr[i].total - average4), 2);

}

std1 = sqrt(deviationSum1 / ((SIZE)-1));

std2 = sqrt(deviationSum2 / ((SIZE)-1));

std3 = sqrt(deviationSum3 / ((SIZE)-1));

std4 = sqrt(deviationSum4 / ((SIZE)-1));

for (int index = 0; index

{

if (index == 0)

standardDeviation[0] = std1;

else if (index == 1)

standardDeviation[1] = std2;

else if (index == 2)

standardDeviation[2] = std3;

else if (index == 3)

standardDeviation[3] = std4;

else

cout

}

}

void print(StudentData[], int[], int[], double[], double[])

{

HELP HERE!!!!!

}

void sort(StudentData arr[])

{

StudentData temp;

for (int i = 0; i

{

for (int j = i + 1; j

{

if (arr[i].last_name > arr[j].last_name)

{

temp = arr[i];

arr[i] = arr[j];

arr[j] = temp;

}

}

}

}

Sample Run Sample Input File grade.dat contains Bonebrake Nicole 90 85 50 78 85 Boyer Dennie 2222 100 90 99 89 88 Bozick Julia 3333 52 85 66 87 Carroll Sandra 4444 87 88 95 85 100 Creighton Sarah 5555 91 55 800 88 75 Everett Terry 6666 60 70 59 79 89 Freeman Andrew 92 95 96 97 Fugett Brandon 8888 88 75 95 80 Sample output: LastName First Name ID userName Test 1 Test 2 Test 3 Test 4 Test 5 Average Grade Bonebrake Nicole 1111 bn1 111 90 85 50 78 85 77.60 C Boyer 93.20 Dennie 2222 bd2222 100 90 99 89 88 66.80 D Bozick Julia 3333 bj3333 52 85 66 87 100 91.00 A Carroll Sandra 4444 cs4444 87 88 95 85 77.80 C Creighton Sarah 5555 cs5555 91 55 80 88 75 Everett Terry 6666 et6666 60 70 59 79 89 71.40 94.80 Freeman Andrew 7777 fa7777 92 95 94 96 97 83.00 B Fugett Brandon 8888 fb8888 77 88 75 95 80 The class average for CS 5 tests is 81.95 The total number of students with grade A is 3 The total number of students with grade B is 1 The total number of students with grade C is 3 The total number of students with grade D is 1 The total number of students with grade F is 0

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Mysql Examples Explanations Explain Examples

Authors: Harry Baker ,Ray Yao

1st Edition

B0CQK9RN2J, 979-8872176237

More Books

Students also viewed these Databases questions

Question

3. Identify cultural universals in nonverbal communication.

Answered: 1 week ago