This program reads number of students and three scores (exams) for every student, then calculates the average, and then displays information in tabular format. For some reason it is not working. I have to write this program using 11 functions so it is not possible to change the format, number of functions, or any big change in the main procedure. Update: I made couple of changes and now I can compile and run it and it displays everything
int student_num (const string & prompt);
void scores (int scores1[], int scores2[],int scores3[], int students);
void sum (int scores1[], int scores2[],int scores3[], int totals[], int students);
double average (int totals[], int students);
double find_max(const int totals[], const int students);
double find_min(const int totals[], const int students);
int above_ave (const int totals[], int students, double ave);
void display (int const scores1[], int const scores2[], int const scores3[], int const totals[], int students, double ave, int mini, int maxi, int n);
void header ();
void body(int const exam1, int const exam2, int const exam3, int total_grade, int st_id, double ave);
void bottom (int students, double ave, int mini, int maxi, int n);
int main()
{
int * scores1;
int * scores2;
int * scores3;
int * totals;
int students(0);
double avg(0.0);
int min, max, above;
string prompt = "Enter number of students: ";
students = student_num (prompt);
scores1 = new int [students];
scores2 = new int [students];
scores3 = new int [students];
totals = new int [3];
scores (scores1, scores2,scores3,students);
sum (scores1, scores2, scores3, totals, students);
int ave = average (totals, students);
int maxi = find_max(totals, students);
int mini = find_min(totals, students);
int n = above_ave (totals, students, ave);
display (scores1, scores2, scores3, totals, students, ave, mini, maxi, n);
delete scores1;
delete scores2;
delete scores3;
delete totals;
return 0;
}
int student_num (const string & prompt)
{
int students, m;
cout << prompt;
cin >> students;
}
return students;
}
void scores (int scores1[], int scores2[],int scores3[], int students)
{
for (int i(0); i<students; i++)
{
cout << "Enter the three scores" << i+1<< ":";
cin >> scores1 [i];
cin >> scores2 [i];
cin >> scores3 [i];
}
}
void sum (int scores1[], int scores2[],int scores3[], int totals[], int students)
{
for (int i(0); i< students; i++)
{
totals[i] = scores1[i] + scores2[i] + scores3[i];
}
}
double average (int totals[], int students)
{
double ave(0), sum (0);
for (int i(0); i<students; i++)
{
sum += totals [i];
}
ave = sum/students;
return ave;
}
double find_max(const int totals[], const int students)
{
double maxi(0); // maximum value of the array
for (int i=0; i<students; i++) //i= loop variable
{
if (totals[i] > maxi)
{
maxi = totals[i];
}
}
return(maxi);
}
double find_min(const int totals[], const int students)
{
double mini = totals [0];
for (int i=1; i<students; i++)
{
if (totals[i] < mini)
{
mini = totals[i];
}
}
return(mini);
}
int above_ave (const int totals[], int students, double ave)
{
int n(0), i(0);
for (int i(0); i<students; i++)
{
if (totals[i] > ave)
{
n++;
}
}
return n;
}
void display (int const scores1[], int const scores2[], int const scores3[], int const totals[], int students, double ave, int mini, int maxi, int n)
{
header();
for (int i(0); i<students; i++)
{
int exam1 = scores1[i];
int exam2 = scores2[i];
int exam3 = scores3[i];
int total_grade = totals[i];
int st_id = i;
body (exam1, exam2, exam3, total_grade, st_id, ave);
}
bottom (students, ave, mini, maxi, n);
}
void body (int const exam1, int const exam2, int const exam3, int total_grade, int st_id, double ave)
{
cout << setw(7) << right << fixed << st_id+1;
cout << setw(10) << left << fixed << exam1;
cout << setw(10) << left << fixed << exam2;
cout << setw(10) << left << fixed << exam3;
cout << setw(5) << left << fixed << total_grade;
if (total_grade > ave)
{cout << setw(2)<<right << "+"<< endl;}
else
{cout << setw(2)<<right << "-"<< endl;}
}
void bottom (int students, double ave, int mini, int maxi, int n)
{
cout << setw(40) << left << "The number of students is:" << setw(7) << left << students<< endl;
cout << setw(40) << left << "The avg total score (rounded) is" << setw(7) << left << int (ave)<< endl;
cout << setw(40) << left << "The maximum total score is:" << setw(7) << left << maxi << endl;
cout << setw(40) << left << "The minimum total score is:" << setw(7) << left << mini << endl;
cout << setw(40) << left << "Total scores at or above the avg is:" << setw(7) << left << n << endl;
}
Studentclass/struct holding the grades, and pass one vector (not pointer, not array) of Students, rather than three separate arrays of related data.scoresfunction. You should start at zero and add 1 to i in your cout call instead of starting i at 1.