1996 A #1

Assume that two arrays (vectors) are used to store information about student's grades. One array contains the students' numerical scores (integers in the range 0..100). The other array contains the corresponding letter grades (characters in the range 'A'..'D').

Assume that a constant
`const int NUM_GRADES` = some positive integer;
has been defined.

Part A
Write the function `LetterAverage`, whose header is given below. `LetterAverage` returns the average (arithmetic mean) of the student scores that correspond to a given letter grade. `LetterAverage` returns 0.0 if none of the student scores corresponds to the given letter grade.

For example, given the following arrays (vectors)

```	StudentScores: 	96	72	84	65	89	60	78	86	75	61	85
StudentLetters:	A	C	B	D	A	D	B	B	C	D	B```
`LetterAverage(StudentScores,StudentLetters,'B')` returns the number 83.25, which is the average of the four scores that correspond to the letter grade B.
`LetterAverage(StudentScores,StudentLetters,'A')` returns the number 92.5, which is the average of the four scores that correspond to the letter grade A.

Complete function `LetterAverage` below the following header.

`double LetterAverage(const apvector & scores, const apvector & letters, char grade)`
// post-condition: returns 0.0 if no element of letters == grade otherwise, returns average of all scores[n],
//      for all 0 <= n < NUM_GRADES, such that letters[n] == grade

Part B
Write the function `Averages`, whose header is given below. `Averages` prints a list of each of the four letter grades ('A'..'D') followed by the average of the student scores that correspond to that letter grade.

For the example given in part (a), the call `Averages(StudentScores,StudentLetters)` prints the following list.

```	A	92.50
B	83.25
C	73.50
D	62.00```

In Writing `Averages` you may call the function `LetterAverage` of part (a). Assume that `LetterAverage` works as specified, regardless of what you wrote in part (a). Complete function `Averages` below the following header

`void Averages(const apvector & scores, const apvector & letters)`

Continue to:  Unit 2  / Prev  / Next