Objective:
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.
| Text File: "RESULTS.TXT" 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.36Here'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) { ... }