Hello,
To start thanks in advance for any help. Now I will note this question is about homework so I just want help to get started not everything laid out for me. Ok here is the deal. I have a class called StudentArrayV4, it is a dynamic array of pointers. I also have the class Student that actually holds the student information and is pointed to by StudentArrayV4. I added the ability to save the student data as well as load it from a file. I made sure the code worked by using (!infile.eof) as my test to find the end of file. However, i know .eof can be unreliable so I don't want to use it, not to mention I'd probably lose points on my homework too. The way I was required to set it up was by having the ifstream opened in main and then passed by reference to StudentArrayV4 which then eventually passes it to the Student Constructor. Any ideas on how I can know when I hit the end of the file without using .eof Here is the code for my various methods.
void StudentArrayV4::read (ifstream& infile){
StudentArrayV4 loadedFile;
if (!infile){
cout << "Error no file found!\n";
}
else{
while (!infile.eof )
add(infile);
}
}
void StudentArrayV4::add (ifstream & infile){
Student **temp = new Student*[numberOfStudents + physicalArraySize];
for (int j = 0; j < numberOfStudents; j++){
temp[j] = members[j];
}
delete [] members;
physicalArraySize += 3;
members = temp;
members[numberOfStudents] = new Student(infile);
numberOfStudents++;
}
Student::Student (ifstream& infile){
char tempName[300];
int length;
infile >> tempName >> idNumber; // loading data from file
for (int j = 0; j < 3; j++){
infile >> scores[j];
}
length = strlen(tempName);
name = new char[length + 1]; // for the null character
strcpy (name, tempName);
calculateAverageAndGrade();
}