Grade Averaging Lab

To implement arrays as apvectors and read data from a text file.
Numeric scores and their corresponding letter grades are stored in a text file. Write a program that reads the data from the text file into two parallel arrays.
  1. Calculate and display each letter grade, followed by the average of scores for that letter grade.
  2. Finally, calculate and display the averages for all the grades.
Build a text file so that each line each contain an integer score in the range of 0 to 100 followed by a space and one of the four letters 'A' through 'D' as shown in the example at right. "RESULTS.TXT' produces an output of the four letter averages and overall average, as shown.
Text File:

96 A
72 C
84 B
65 D
89 A
60 D
78 B
86 B
75 C
61 D
85 B

Letter     Average
A  	    92.50
B	    83.25
C	    73.50
D	    62.00
The overall average is 77.36
Here's a template for reading data from your text file -
#include <fstream.h>	// for file I/O

apvector<int> scores (/*how are you going to size your arrays?*/);
apvector<char> letters (/*some positive integer*/);
ifstream infile("results.txt");  	// or complete path ("a:\\unit2\\code\\results.txt")
if (! infile)
	{	cout << "File could not be opened." << endl;
		exit(1);	// terminate program
int val;
char letter;
while (infile >> val >> letter)
	{ ... }

Continue to:  Unit 1  / Prev  / Next