86.4k views
5 votes
This is c++

Write a program that will open and read in data containing student names followed by their four grades separated by spaces on each line of the input file (download input.txt linked above). You should store the data for each student and their four grades within 5 parallel vectors of the appropriate data type. Note: the student name vector is a vector of strings and the rest are vectors of either floats or doubles. Once you have read in all of the names, then you should close your input file and start a new loop to process and calculate the average grade for each student one at a time where you will write out each student’s name and their course average line by line to your output file. Then close the output file.
This is what is on the input.txt
Alice 92 87 94 99
Chris 91 96 93 100
Eric 88 82 85 87
John 52 68 63 72
Martin 33 48 52 69
Catherine 72 78 88 89
Victoria 91 96 93 100

1 Answer

0 votes

Final answer:

A C++ program to read a file with student names and grades into vectors, calculate averages, and write the results to an output file consists of several steps including file I/O with fstream and data manipulation within vectors.

Step-by-step explanation:

Reading and Processing Data from a Text File

In C++, reading and processing data from a text file into parallel vectors is a common task. In the classroom exercise, students will extract student names and their grades from a file, calculate the average grades, and write the results to an output file. The program will utilize the fstream library to handle file operations and the vector container from the STL to store the data. The process involves opening the input file, reading the contents into vectors, computing the average grades, and then writing each student's name and their course average to an output file.

Steps for Implementing the Program









To ensure that the vectors stay parallel, it's crucial to maintain consistent indexing across all of them. Using floats or doubles for grades depends on the precision requirements of the task.

User MattDiMu
by
7.2k points