/* Assignment 10: This program's purpose is to figure out a curve for tests. /* Author: Nicholas Della Vecchia Email: Negativecreep0@yahoo.com */ /* Date: 4/10/01 */ #include /* this function validates a certain number (number) to make sure its within the limits (min and max )specified by user */ double validate(double min, double max, double number) { /* simple while statement makes sure number is valid if it isn't it continues looping printing the invalid message until a valid input is entered */ while ((number < min) || (number > max)) { printf ("Invalid Value !! Please enter a value between %.2f and %.2f: ",min,max); scanf ("%lf",&number); printf ("\n"); } /* the valid number is returned */ return number; } /* this function determines the lowest number within the array of grades using*/ double lowest(int students,double grades[]) { /* variable for counter */ int i; /* variable for the lowest score to be returned */ double low; /* the variable low is set to a ridiculously high value so that the first element in the array can replace it as the new low */ low = 1000; for (i=0; i < students; i ++) { /* if grades[i] is less than low then that element of the array becomes the new low */ if (grades[i] < low) { low = grades[i]; } } /* the lowest number is returned */ return low; } /* this function determines the highest number within the array of grades. */ double highest(int students,double grades[]) { /* variable for counter */ int i; /* variable for high score to be returned */ double high; /* the variable high is set to a ridiculously low value so that the first element in the array can replace it as the new high */ high = -1; for (i=0; i < students; i ++) { /* if grades[i] is greater than high then that element of the array becomes the new high */ if (grades[i] > high) { high = grades[i]; } } /* the highest score is returned */ return high; } /* this function determines the middle mean of all the grades */ double midmean(double low, double high, int students, double grades[]) { /* variable for counter */ int i; /* variable for middle mean to be returned */ double mean; /* variable for number of tests */ int tests; /* variable for total sum of all grades */ double total; /* in order to get the middle mean you must remove the highest and lowest scores from the array so to make up for the loss of these two tests the new tests number is subtracted by two so proper averaging can be done on the remainder of the grades */ tests= (students - 2); /* total set to 0 so it can be added to itself later */ total = 0; /* for loop goes through the array of scores and adds them all up */ for (i=0; i < students; i++) { total = (total + grades[i]); } /* to get the middle mean the value of the lowest and highest grades are subtracted from the total grades, eliminating the high and low grade from the averaging (which aren't needed) the sum is then divided by the number of tests left */ mean = ((total) - (low + high))/(tests); /* the middle mean is returned */ return mean; } /* I decided to keep my main function organized so I decided to use a function for printing out the grade report at the end, this function is void since it does not return any values */ void gradereport(double grades[], int students, double curve) { int i; /* variable to keep track of number of A grades */ double agrades; /* variable for the percent of A grades out of all grades */ double percent; printf ("Student Grade Report:\n\n"); printf ("\tStudent\t Score\t\t A\n\n"); printf ("\t=======\t =====\t\t===\n"); agrades = 0; /* for loop which prints out the data on the student showing their new grade and determining if they recieved an A and */ for (i=0; i < students; i++) { /* if grade is equal to an A the normal components with curve are printed out with an extra * at the end */ if ((grades[i]+curve) >= 92) { printf ("\t%4d\t%9.1f\t\t *\n",i+1,grades[i]+curve); /* 1 is added to the agrades variable if the grade is an A */ agrades = agrades +1; } else /* if grade is not an A then student, and grade with curve are printed */ printf ("\t%4d\t%9.1f\n",i+1,grades[i]+curve); } /* percentage of A students is calculated */ percent = ((agrades/students) * 100); printf ("\n%.0f of %d students got A's. That's %.2f percent\n\n\n",agrades,students,percent); } int main() { /* initialization of the array scores with max elements of 120 */ double scores[120]; /* variable for counter */ int i; /* variable for highest score */ double high; /* variable for lowest score */ double low; /* variable for the number of students being handled */ int numstudents; /* variable for curve */ double curve; /*variable for the middle mean */ double middlemean; printf ("Welcome to Dr. Della Vecchia's Test Score Program\n"); printf ("How many students? Please enter a value between 3 and 100: "); scanf ("%d",&numstudents); printf ("\n"); printf ("\n"); /* checking if numstudents is valid between and including ranges from 3 and 100 */ numstudents = validate(3,100,numstudents); /* for loop which initializes each element in the array with the students grade for the test */ for (i=0; i < numstudents; i++) { printf ("Enter score for student %d, Please enter a value between 0.00 and 100.00 ==> ",i+1); scanf ("%lf",&scores[i]); printf ("\n"); /* checking if the score entered is valid and in the rang from 0 to 100 */ scores[i]=validate(0,100,scores[i]); printf ("\n"); } /* returning the lowest function value to low */ low=lowest(numstudents, scores); /* returning the high function value to high */ high=highest(numstudents, scores); /* returning the midmean function value to middlemean */ middlemean=midmean(low,high,numstudents,scores); printf ("Middle Mean is: %.1f\n",middlemean); /* determining the curve by subtracting the middle mean from 80 */ curve = (80 - middlemean); /* if the middle mean is less than 80 the proper curve is printed */ if (middlemean < 80) printf ("Curve is: %.1f\n",curve); /* else if middle mean is 80 or greater than the curve is set to 0 */ else { curve = 0; printf ("Curve is: %.1f\n",curve); } printf ("\n"); /* the gradereport function is run and the final report is displayed */ gradereport(scores, numstudents, curve); }