The bottom three functions do not work. Nor are the finished to the extent.
I do not know how the data members are being accessed and is only giving me
the last output. The overall goal of this program is to output the highest grade with student name and age, lowest grade with student name and age, and the average of all grades. The file is given and is commented out for you to see what the file looks like.
// loop through file to max string length
for( index = 0; index < STD_STR_LEN; index++ ) {
// acquire data for each statement
fin >> info.firstName >> info.lastName >> info.age >> info.gradePercentage;
}
This code will read first student in info. Then it will read second student in info, overwriting first. Then third, etc.
If you need to read many students, you either should read one at a time, do all operations with it, then read next... Or you need to read them in some container, like vector.
Your problem(s) start at line 29. You have only one student. On line 54 you overwrite that student STD_STR_LEN times, so you only keep the data of the last student.
You should have a list/vector/array of students and pass that to the functions. Assuming that the input file contains exactly STD_STR_LEN records is too static. You should learn to make generic and robust programs that lack such assumptions.
Using plain char arrays for the name fields is error-prone. You should use std::string instead.
Thanks for the help from both. Keskiverto, for the purposes of this project, we were not allowed to use the string library and for both, we are not allowed to use vectors. And for being early in the programming field, we have to assume a lot of things for now to learn what will happen.
The use of vector is not necessary, but "borrowing" ideas from it is useful. The vector has capacity (how many elements it can hold) and size (how many elements it has now). You can emulate that with an array and variables:
1 2 3
const size_t capacity = 100; // How many students we can handle at most
size_t size = 0; // How many students we have
student sinfo [capacity]; // the students
When you read a new student from file, you store it into the next element in sinfo and increment the size by one. However, you can not read more than capacity lines. That is a simple check.
The other methods then iterate over size elements of the sinfo.