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 from hard coded data. We can design a function to replace that which gets real data from the file and returns a vector with the students. 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 gets used by test code and a larger real 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.