C This program read scores from a file and assigns grades on a C curve. The calculation of the mean, standard deviation, and C assignment of the letter grade are all handled by functions. C A subroutine is used to read the data. C C John Schneider C CptS 203, HW 8, Problem 1. C-------------------------------------------------------------------------- program disp implicit none real grades(200), m, sigma, mean, stddev integer nelem, i character grade call setary(grades,nelem) m = mean(grades,nelem) sigma = stddev(grades,nelem,m) print *, 'Average = ',m,', standard deviation = ',sigma do 10 i=1,nelem print *, 'Student ',i,', score = ',grades(i), & ', grade = ',grade(grades(i),m,sigma) 10 continue stop end C*************************** end of main program ************************* C......................................................................... C Subroutine to read values from a file into a one-dimensional C real array. C..... subroutine setary(a,n) implicit none real a(*) integer n character filnam*50 print *, 'Enter the input file name.' read '(a)', filnam open(unit=12,file=filnam,status='old') n = 1 10 read(12,*,end=20)a(n) n = n+1 goto 10 20 continue n = n-1 print *, 'Number of values read: ',n return end C********************** end of subroutine setary() *********************** C......................................................................... C Function to find the mean value of a real array with "n" elements. C..... real function mean(a,n) implicit none real a(*) integer i, n mean = 0.0 do 10 i=1,n mean = mean + a(i) 10 continue mean = mean/n return end C************************ end of function mean() ************************* C......................................................................... C Function to find the standard deviation of a real array with "n" C elements and a mean of "m". C..... real function stddev(a,n,m) implicit none real a(*), m integer i, n stddev = 0.0 do 10 i=1,n stddev = stddev + (a(i) - m)**2 10 continue stddev = sqrt(stddev/n) return end C*********************** end of function stddev() ************************ C......................................................................... C Function to find the grade given the score (s), mean (m), and C standard deviation (sigma). Grades assigned as follows: C s < m - 1.5 sigma => F C m - 1.5 sigma <= s < m - 0.5 sigma => D C m - 0.5 sigma <= s < m + 0.5 sigma => C C m + 0.5 sigma <= s < m - 1.5 sigma => B C m + 1.5 sigma <= s => A C..... character function grade(s,m,sigma) implicit none real s, m, sigma if (s .LT. m - 1.5*sigma) then grade = 'F' elseif (s .LT. m - 0.5*sigma) then grade = 'D' elseif (s .LT. m + 0.5*sigma) then grade = 'C' elseif (s .LT. m + 1.5*sigma) then grade = 'B' else grade = 'A' endif return end C************************ end of function mean() *************************