#include #define NUMSTUDENTS 40 #define NUMGRADES 5 /* A, B, C, D, F */ #define A 0 #define B 1 #define C 2 #define D 3 #define F 4 #define FALSE 0 #define TRUE 1 void read_scores(char[], float[], float[]); void copy(float[], float[], int); float mean(float[], int); void sort(float[], float[], int); float median(float[], int, int); float max(float[], int, int); float min(float[], int, int); void count_grades(float[], int[], int); float mean_delta(float[], float[], int); int main() { float ex1[NUMSTUDENTS]; float ex2[NUMSTUDENTS]; float ex1_sorted[NUMSTUDENTS]; float ex2_sorted[NUMSTUDENTS]; int gc1[NUMGRADES]; int gc2[NUMGRADES]; float mean1, mean2; float median1, median2; float min1, min2; float max1, max2; float mean_change; read_scores("grades.dat", ex1, ex2); mean1 = mean(ex1, NUMSTUDENTS); mean2 = mean(ex2, NUMSTUDENTS); sort(ex1, ex1_sorted, NUMSTUDENTS); sort(ex2, ex2_sorted, NUMSTUDENTS); median1 = median(ex1_sorted, NUMSTUDENTS, TRUE); median2 = median(ex2_sorted, NUMSTUDENTS, TRUE); min1 = min(ex1_sorted, NUMSTUDENTS, TRUE); min2 = min(ex2_sorted, NUMSTUDENTS, TRUE); max1 = max(ex1_sorted, NUMSTUDENTS, TRUE); max2 = max(ex2_sorted, NUMSTUDENTS, TRUE); count_grades(ex1, gc1, NUMSTUDENTS); count_grades(ex2, gc2, NUMSTUDENTS); mean_change = mean_delta(ex1, ex2, NUMSTUDENTS); printf("\n"); printf("Grade Statistics\n\n"); printf("\tExam 1\tmedian = %.2f\tmean=%.2f\tmin=%.2f\tmax=%.2f\n", median1, mean1, min1, max1); printf("\tExam 2\tmedian = %.2f\tmean=%.2f\tmin=%.2f\tmax=%.2f\n", median2, mean2, min2, max2); printf("\n"); printf("Grade Distribution\n\n"); printf("\tExam 1\tA:%d\tB:%d\tC:%d\tD:%d\tF:%d\n", gc1[A], gc1[B], gc1[C], gc1[D], gc1[F]); printf("\tExam 2\tA:%d\tB:%d\tC:%d\tD:%d\tF:%d\n", gc2[A], gc2[B], gc2[C], gc2[D], gc2[F]); printf("\n"); printf("Mean delta (ex2 - ex1) is %f\n\n", mean_change); return 0; } void read_scores(char file[], float ex1[], float ex2[]) { FILE *fp; int i; fp = fopen(file, "r"); for (i=0; i y[i+1]) { tmp = y[i]; y[i] = y[i+1]; y[i+1] = tmp; swapped = TRUE; } } if (!swapped) { done = TRUE; } } return; } float max(float x[], int len, int sorted) { float y[len]; if (!sorted) { sort(x, y, len); return y[len-1]; } else { return x[len-1]; } } float min(float x[], int len, int sorted) { float y[len]; if (!sorted) { sort(x, y, len); return y[0]; } else { return x[0]; } } void count_grades(float x[], int grades[], int len) { int i; for (i=0; i= 90.0) { grades[A]++; } else if (x[i] >= 80.0) { grades[B]++; } else if (x[i] >= 70.0) { grades[C]++; } else if (x[i] >= 60.0) { grades[D]++; } else { grades[F]++; } } return; } float mean_delta(float x[], float y[], int len) { float z[len]; float ans; int i; for (i=0; i