"fill" is a terrible name for a function to read a file.
Don't loop on EOF.
The assignment is unclear about the text file format.
May there be more than one student listed in the file?
Must all the test scores be on the same line?
(The only thing it is clear about is the whitespace stuff, which is actually an insignificant issue when reading the file.)
I don't understand your use of language. (The best I can get out of your filename is something about dead cats?)
I will assume
multiple students may be listed in the file, since it is a worst-case kind of scenario, and the resulting thought will work even if there is only one student listed.
So, here is an example file that covers all possibilities:
Com Truise
34.5 40 50 80
Livien Veigh
74.3
88.5
90
100 |
Q. How would you store this information?
A. For each
student, you need a
name and a
list of grades, right?
For a name, you need a string. (Just one!)
For a list of grades, you need a vector of doubles.
To hold a student, you need a struct/class.
1 2 3 4 5
|
struct Student
{
string name;
vector <double> grades;
};
|
If your file contains only one student, you'll want something like:
1 2 3 4
|
int main()
{
Student student;
...
|
If your file contains multiple students, you'll want a vector of them, right?
1 2 3 4
|
int main()
{
vector <Student> students;
...
|
Either way, you also need a function to read a single student from file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
Student read_student( ifstream& file )
{
Student student;
// First, read the student's name
// Then you need a loop to read grades, until the loop fails.
while (file >> grade)
{
// Once you have a grade, add it to the list of grades
}
// At this point, it makes a difference whether you have hit EOF or not.
// If you have, then leave the file in its error state. Otherwise you must
// clear it for the next student (or whatever other kind of thing may be
// in the file).
if (!file.eof()) file.clear();
return student;
}
|
You can use this easily enough:
1 2 3 4 5 6 7 8
|
int main()
{
Student student;
ifstream fin("Tot Katzen.txt");
student = read_student(fin);
...
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
|
int main()
{
vector <Student> students;
ifstream fin("Tot Katzen.txt");
while (true)
{
// Try to read a student from the file
Student student = read_student(fin);
// Only if a student could not be read, quit reading from file
if (!fin) break;
// Otherwise, add the student just read to our list of students
students.push_back(student);
}
...
|
Now you have to deal with deleting the lowest score and computing the average of the/each student's grades.
Good luck!