# Letter Grade Computation Using Assumed-Shape Arrays

### Problem Statement

Suppose there are n score values x1, x2, ..., xn. Let its mean and standard deviation be m and s. A letter grade is assigned to each score based on the following scale:

The mean, variance and standard deviation are computed with the following formulae:

Write a program that uses assumed-shape arrays.

### Solution

```! --------------------------------------------------------------------
!    This program reads in a set of values, computes its mean,
! variance, and standard deviation, and use the mean and standard
! deviation to compute a letter grade.
!    This program shows you passing arrays as arguments with assumed-
! shape arguments.  Since all lower bounds are 1, no extent
! information are passed.
! --------------------------------------------------------------------

IMPLICIT  NONE

INTEGER, PARAMETER :: MAX_SIZE = 100
REAL, DIMENSION(1:MAX_SIZE) :: InputData
INTEGER                     :: ActualSize

CALL  DisplayResult(InputData, ActualSize)

CONTAINS

! --------------------------------------------------------------------
!    This subroutine reads in the number of data and the data set.
! --------------------------------------------------------------------

IMPLICIT  NONE
INTEGER, INTENT(OUT)             :: n
REAL, DIMENSION(1:), INTENT(OUT) :: x
INTEGER                          :: i

READ(*,*)  (x(i), i = 1, n)

! --------------------------------------------------------------------
! SUBROUTINE  DisplayResult():
!    This subroutine calls MeanVariance() to compute the mean,
! variance and standard deviation, and prints a grade report.  The
! --------------------------------------------------------------------

SUBROUTINE  DisplayResult(Data, n)
IMPLICIT  NONE
INTEGER, INTENT(IN)             :: n
REAL, DIMENSION(1:), INTENT(IN) :: Data
INTEGER                         :: i
REAL                            :: Mean, Var, Std

CALL  MeanVariance(Data, n, Mean, Var, Std)
WRITE(*,*)
DO i = 1, n
WRITE(*,*) Data(i), "  ", LetterGrade(Data(i), Mean, Std)
END DO
WRITE(*,*)
WRITE(*,*)  "No. of students          = ", n
WRITE(*,*)  "Class average            = ", Mean
WRITE(*,*)  "Class variance           = ", Var
WRITE(*,*)  "Class standard deviation = ", Std
END SUBROUTINE  DisplayResult

! --------------------------------------------------------------------
!    This function receives a score and the mean and standard deviation
! values, and returns a letter grade.
! --------------------------------------------------------------------

IMPLICIT  NONE
REAL, INTENT(IN) :: x, Mean, StdDev

IF (x < Mean - 1.5*StdDev) THEN
ELSE IF (x < Mean - 0.5*StdDev) THEN
ELSE IF (x < Mean + 0.5*StdDev) THEN
ELSE IF (x < 1.5*StdDev) THEN
ELSE
END IF

! --------------------------------------------------------------------
! SUBROUTINE  MeanVariance():
!    This subroutine computes the mean, variance and standard
! deviation.
! --------------------------------------------------------------------

SUBROUTINE  MeanVariance(Data, n, Mean, Variance, StdDev)
IMPLICIT  NONE
INTEGER, INTENT(IN)             :: n
REAL, DIMENSION(1:), INTENT(IN) :: Data
REAL, INTENT(OUT)               :: Mean, Variance, StdDev
INTEGER                         :: i

Mean = 0.0
DO i = 1, n
Mean = Mean + Data(i)
END DO
Mean = Mean / n

Variance = 0.0
DO i = 1, n
Variance = Variance + (Data(i) - Mean)**2
END DO
Variance = Variance / n
StdDev   = SQRT(Variance)
END SUBROUTINE  MeanVariance

```

### Program Input and Output

If the input data consist of the following:
```10
78.0  90.0  55.0  95.0  64.0
87.0  73.0  92.0  85.0  80.0
```
The output of the program is:
```Grading Report

78.  C
90.  A
55.  F
95.  A
64.  D
87.  A
73.  D
92.  A
85.  C
80.  C

No. of students          = 10
Class average            = 79.9000015
Class variance           = 147.690002
Class standard deviation = 12.1527777
```