Skip to main content

Section 15.13 Case Study: Students - Part 3

All that is left is to read in the data from the file. Time to tackle that.

Subsection 15.13.1 Reading the File

The previous exercise had a function getTestStudents() that created a few students we could use to test our code with. To make the program work with the data in the file, we can design a similar function that reads that data and returns a vector of students. Then we can swap the call to getTestStudents() with a call to this new function.
It might be useful for the function to take the filename to read from as its parameter. That would make it possible to have a smaller test file that we can use for testing a larger file that gets used by the final program.
We already have functions that will take an entire line of text and create a Name or a Status or a vector of doubles. So all this function has to do is to use getline 3 times for each student. We will assume that we don’t know how many students there are in the file, so we will read until eof.

Checkpoint 15.13.1.

Construct the algorithm for getStudentData. Make sure to check for failure after trying to read in the next three lines before using them to make a student.
You have attempted of activities on this page.