He called it that way because the function returns the count variable, which is keeping track of how many scores have been read in (and iterating the index up as well).
Essentially all he wants you to do is duplicate his code for the other two arrays. I'll attempt to explain what he's doing.
1 2
|
ifstream inFile;
int count = 0;
|
Here he declares a stream that he will use to process the files and an integer counter that he initializes to 0.
1 2 3 4 5 6
|
inFile.open("scores.txt");
if (inFile.fail())
{
cout << "Unable to open scores.txt file\n";
exit(1);
}
|
Here he opens the file and checks to make sure it opens correctly (the if statement with infile.fail() condition does that)
1 2 3 4 5 6 7 8 9
|
inFile >> exam1Array[count];
while (!inFile.eof())
{
/*read Exam 2 and Exam 3 scores for this student into their respective arrays*/
count++;
inFile >> exam1Array[count];
}
|
This is the real meat of the function. He usese the >> operator to pull in the first score from the file (infile) and then starts a loop that pulls in each subsequent score by increasing the index on the array (count is being used as the index). This loop will continue until the end of the file (or eof, hence the infile.eof() condition in the while). Since infile.eof() returns true when the end has been reached (and the loop must be true to continue running), he uses the '!' symbol to keep running the loop until eof triggers.
1 2 3
|
inFile.close();
return count;
|
He then closes the stream and returns count (which is the value that gets stored in size when he calls the function as you showed in the example.
The one thing I'm not sure about is why only one parameter is being passed to the buildArrays function that you showed. Was the example for the same function or a different one that only took one array?