Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

c++ You are a grader in your History class. The professor has asked you to prepa

ID: 3717141 • Letter: C

Question

c++

You are a grader in your History class. The professor has asked you to prepare the following statistics for the final exams for each of the last five (5) semesters: number of student grades, the class average exam grade, number of grades above the average and the number of grades below the average. You decide to write a program to read the data, perform the needed calculations and print the report.

Use the following input file called "infile.txt":

Requirements

Define an examType struct to store the data for each final exam. Each instance of this user-define type should contain thesemester_name, the semester_year, the no_of _grades, the average_grade, the no_of_grades_above_average, no_of_grades_below_average and a grades_array of 35 integers that will store up to 35 student grades for the semester final exam. (See data file above)

The main() function must define an array (statistics_array) of five (5) examType structs. Then call the three (3) functions indicated in the structure chart above.

The input_data() function takes in two parameters, the infile and the statistics_array. This function reads (loops) through the five sets of semester final exam data and populates a portion of the statistics_array.

The calculate_statistics() function takes in the statistics_array and then loops five times calling the calculate_average(), calculate_above_average() and calculate_below_average() functions sending the semester_index (0 -4) and the statistics_array to each function. The result is that these computed statistics are stored in each of member structs in the statistics_array.

The calculate_average() function takes in the statistics_array and a semester_index. This function loops through the grades_array in the struct indicated by the semester_index and sums all the grades. This sum is divided by the no_of _grades in the member struct (indexed by semester_index) to compute the average grade for that semester's final exam. Finally, this average is stored in the average_grade member of the struct indexed by the semester_index .

The calculate_above_average() function takes in the statistics_array and a semester_index. This function loops through the grades_array in the struct indexed by the semester_index and counts all the grades that are above the average_grade member of the struct indexed by the semester_index. Finally, this count is stored in the no_of_grades_above_average member of the struct indexed by the semester_index.

The calculate_below_average() function takes in the statistics_array and a semester_index. This function loops through the grades_array in the struct indexed by the semester_index and counts all the grades that are below the average_grade member of the struct indicated by the semester_index. Finally, this count is stored in the no_of_grades_below_average member of the struct indexed by the semester_index.

The print_results() function takes in the statistics_array and loops through it printing the exam information stored for each semester. This function prints the report show below:

You are a grader in your History class. The professor has asked you to prepare the following statistics for the final exams for each of the last five (5) semesters: number of student grades, the class average exam grade, number of grades above the average and the number of grades below the average. You decide to write a program to read the data, perform the needed calculations and print the report.

Use the following input file called "infile.txt":

Requirements

Define an examType struct to store the data for each final exam. Each instance of this user-define type should contain thesemester_name, the semester_year, the no_of _grades, the average_grade, the no_of_grades_above_average, no_of_grades_below_average and a grades_array of 35 integers that will store up to 35 student grades for the semester final exam. (See data file above)

The main() function must define an array (statistics_array) of five (5) examType structs. Then call the three (3) functions indicated in the structure chart above.

The input_data() function takes in two parameters, the infile and the statistics_array. This function reads (loops) through the five sets of semester final exam data and populates a portion of the statistics_array.

The calculate_statistics() function takes in the statistics_array and then loops five times calling the calculate_average(), calculate_above_average() and calculate_below_average() functions sending the semester_index (0 -4) and the statistics_array to each function. The result is that these computed statistics are stored in each of member structs in the statistics_array.

The calculate_average() function takes in the statistics_array and a semester_index. This function loops through the grades_array in the struct indicated by the semester_index and sums all the grades. This sum is divided by the no_of _grades in the member struct (indexed by semester_index) to compute the average grade for that semester's final exam. Finally, this average is stored in the average_grade member of the struct indexed by the semester_index .

The calculate_above_average() function takes in the statistics_array and a semester_index. This function loops through the grades_array in the struct indexed by the semester_index and counts all the grades that are above the average_grade member of the struct indexed by the semester_index. Finally, this count is stored in the no_of_grades_above_average member of the struct indexed by the semester_index.

The calculate_below_average() function takes in the statistics_array and a semester_index. This function loops through the grades_array in the struct indexed by the semester_index and counts all the grades that are below the average_grade member of the struct indicated by the semester_index. Finally, this count is stored in the no_of_grades_below_average member of the struct indexed by the semester_index.

The print_results() function takes in the statistics_array and loops through it printing the exam information stored for each semester. This function prints the report show below:

Main infile statistics array statistics array statistics larrav. Print_ Results Input_Data Calculate Statistics semester index semester index statistics larray statistics arrav statistics array semesterlindex Calculate_ Average Calculatee Above Average Calculate Below Average

Explanation / Answer

Before executing the below c++ program code we have to a create text file named "infile.txt" with the content given in question & save the file in current working directory where c++ program is stored.

C++ Program

#include <iostream> //used for cin, cout

#include <fstream> // used for file handling functions & streams

#include <stdlib.h> // used for exit() function

#include <iomanip> // used for setprecision() function

using namespace std;

//Structure defination to store the data for each final exam

struct examType

{

char semester_name[10];

int semester_year;

int no_of_grades;

float average_grade;

int no_of_grades_above_average, no_of_grades_below_average;

int grades_array[35];

};

//Function reads the data from "infile.txt" & store it into statistics_array

void input_data(char infile[],struct examType statistics_array[])

{ int i,j;

ifstream fin;

fin.open(infile);

if(!fin) {

cout<<"File can not be opened"<<endl;

exit(1);

}

for(i=0;i<5;i++)

{

fin>>statistics_array[i].semester_name;

fin>>statistics_array[i].semester_year;

fin>>statistics_array[i].no_of_grades;

for(j=0;j<statistics_array[i].no_of_grades;j++)

{ fin>>statistics_array[i].grades_array[j]; }

}

fin.close();

}

//function will calculate class average exam grade

void calculate_average( int semester_index,struct examType statistics_array[])

{ int i,sum_grades=0;

for(i=0;i<statistics_array[semester_index].no_of_grades;i++)

{

sum_grades+=statistics_array[semester_index].grades_array[i];

}

statistics_array[semester_index].average_grade = (float) (sum_grades)/(float)(statistics_array[semester_index].no_of_grades);

}

//function will calculate number of grades above the average  

void calculate_above_average(int semester_index,struct examType statistics_array[])

{ int i,count=0;

  

for(i=0;i<statistics_array[semester_index].no_of_grades;i++)

{

if(statistics_array[semester_index].grades_array[i]>statistics_array[semester_index].average_grade)

{ count++;}

}

statistics_array[semester_index].no_of_grades_above_average = count;

}

//function will calculate number of grades below the average

void calculate_below_average(int semester_index,struct examType statistics_array[])

{ int i,count=0;

  

for(i=0;i<statistics_array[semester_index].no_of_grades;i++)

{

if(statistics_array[semester_index].grades_array[i]<statistics_array[semester_index].average_grade)

{ count++;}

}

statistics_array[semester_index].no_of_grades_below_average = count;

}

//function will call three functions to calculate avearge, above_average, below_average

void calculate_statistics(struct examType statistics_array[])

{ int semester_index;

for(semester_index =0; semester_index <5; semester_index ++)

{

calculate_average( semester_index,statistics_array);

calculate_above_average(semester_index,statistics_array);

calculate_below_average(semester_index,statistics_array);

}

}

//Function will print the exam information stored for each semester

void print_results(struct examType statistics_array[])

{ int i;

for(i=0;i<5;i++)

{

cout<<"Analysis of exams in "<<statistics_array[i].semester_name<<" "<<statistics_array[i].semester_year<<endl<<endl;

cout<<"The number of grades is "<<statistics_array[i].no_of_grades<<endl;

cout<<"The average grade is "<<fixed<<setprecision(2)<<statistics_array[i].average_grade<<endl;

cout<<"The number of grades above the average is "<<statistics_array[i].no_of_grades_above_average<<endl;

cout<<"The number of grades above the average is "<<statistics_array[i].no_of_grades_below_average<<endl<<endl;

} //end of for loop

} //end of print_results() function

//main() function calling other functions

int main()

{

struct examType statistics_array[5];

char infile[]="infile.txt";

input_data(infile,statistics_array);

calculate_statistics(statistics_array);

print_results(statistics_array);

return(1);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote