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

Write a program that will hold student records and perform a statistical analysi

ID: 3860714 • Letter: W

Question

Write a program that will hold student records and perform a statistical analysis of a class of 10 students. During the semester, each student will have taken 3 tests, each worth 100 points. Each student is identified by a 5-digit student ID number, and their first and last name and last name, followed by their respective three test scores.

Read the input data from the input file (shown below) called info.txt. Note that the data is stored in the format: studentID, first name, last name, test1, test2, and test3.

12345 Eugene Gautier 56 67 78

11111 Silas Maginot 87 99 23

23265 Alena Aspen 77 97 55

39485 Karina Elihu 88 95 67

86768 Arlette Smith 76 85 49

86124 Phillip Eadwig 88 55 100

5472 Ruth Merrill 75 66 44

28394 Sebastian Heinrich 75 75 75

54634 Oliver Bennett 87 78 87

54328 Douglas Koert 99 44 78

Chose one student from the file and read each line of data. Then, place the information into a struct variable. This means that you will need an array of structs to store the data that was read from the input file. This will be a 1-dimensional array.

One at a time, read the data line for each student and place the information into a struct variable. This means that you will need an array of structs to store the data from all the students. To achieve this, read from the input file. This will be a 1-dimensional array.

After you have read the data from the file to the array, calculate and display the following statistics for each exam.

Number of students

Lowest score

Highest score

Average score rounded to 2nd decimal place

Explanation / Answer

#include<stdio.h>

#include<stdlib.h>

//define to hold MAX of 100 student

#define MAX 100

typedef struct

{

unsigned int ID;

char firstName[20];

char lastName[20];

int test[3];

}StudentInfo;

//function to find max and min

void minTestScore(StudentInfo info[], int count, int *min, int index);

void maxTestScore(StudentInfo info[], int count, int *max, int index);

int findsum(StudentInfo info[], int count, int index);

int main()

{

//declare array of struct to hold student info

StudentInfo info[MAX];

FILE *fp;

int i = 0, j,k;

//min and max array to hold for 3 tests

int min[3], max[3];

int *sum;

float *Avg;

//open info.txt file and fill the array of struct

fp = fopen("info.txt", "r");

if (!fp)

{

printf("Unable to open file info.txt ");

return -1;

}

//while (fscanf(fp, "%d%s%s%d%d%d", &info[i].ID, info[i].firstName, info[i].lastName, &info[i].test1, &info[i].test2, &info[i++].test3));

while (fscanf(fp, "%d%s%s%d%d%d", &info[i].ID, &info[i].firstName, &info[i].lastName, &info[i].test[0], &info[i].test[1], &info[i].test[2]) != EOF)

{

i++;

}

sum = (int*)malloc(sizeof(int)*3);

Avg = (float*)malloc(sizeof(float)*3);

//now calculate avg

for (j = 0; j < 3; j++)

{

sum[j] = findsum(info,i,j);

}

//Average is sum of all the tests divided by number of students

for (j = 0; j < 3; j++)

{

Avg[j] = (float)sum[j] / i;

}

//find min and max

for (k = 0; k < 3; k++)

min[k] = info[0].test[0];

for (k = 0; k < 3; k++)

max[k] = info[0].test[0];

for (k = 0; k < 3; k++)

{

minTestScore(info, i, &min[k], k);

maxTestScore(info, i, &max[k], k);

}

//now print all the info to standard output

printf("Number of students: %d ", i);

for (k = 0; k < 3; k++)

{

printf("Min score in test%d = %d ", k + 1, min[k]);

printf("Max score in test%d = %d ", k + 1, max[k]);

printf("Average score for test%d = %.2f ", k + 1, Avg[k]);

}

}

void minTestScore(StudentInfo info[], int count, int *min,int index)

{

int k;

for (k = 0; k < count; k++)

{

if (*min > info[k].test[index])

{

*min = info[k].test[index];

}

}

}

void maxTestScore(StudentInfo info[], int count, int *max,int index)

{

int k;

for (k = 0; k < count; k++)

{

if (*max < info[k].test[index])

{

*max = info[k].test[index];

}

}

}

int findsum(StudentInfo info[], int count, int index)

{

int k = 0,sum = 0;

for (k = 0; k < count; k++)

{

sum += info[k].test[index];

}

return sum;

}

----------------------------------------------------------------

//output

Number of students: 10
Min score in test1 = 56
Max score in test1 = 99
Average score for test1 = 80.80
Min score in test2 = 44
Max score in test2 = 99
Average score for test2 = 76.10
Min score in test3 = 23
Max score in test3 = 100
Average score for test3 = 65.60

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