If anyone could, I need help accessing a score of a student in order to change that grade. Here is the code for it:
1 2 3 4 5 6 7 8 9 10 11
void changeScore(Student* gradeBook, string name, int assignmentNum, int changeGrad, int numScores, int numStudents)
{
for (int i = 0; i < numScores; i++)
{
if (gradeBook[i].fullName == name)
{
gradeBook[i].scores[assignmentNum] = changeGrad;
}
}
}
Here is the file:
1 2 3 4 5 6 7
Sam Thomas 1 81 90 95 78
Sue Conner 0 67 80 81 79
Dan Gordon 1 90 91 88 93
Pam Roberts 1 93 89 78 90
Joe Sullivan 1 98 91 89 97
Liz Collins 0 57 70 63 72
kIM sHAWN 0 89 92 90 92
I think my issue is that I can't directly relate the name to a position in gradeBook and I'm only reading the last student. I don't understand how to fix it. Any help would be greatly appreciated!
In another thread I suggested that you use vectors. Look at how easy this is when you do it that way:
1 2 3 4 5 6 7 8 9 10
// Find the named student in gradebook. Then change that student's grade for
// assignment "assignmentNum" to "newGrade"
void changeScore(vector<Student> &gradebook, string name, int assignmentNum, int newGrade)
{
for (unsigned i=0; i<gradebook.size(); ++i) {
if (gradebook[i].name == name) {
gradebook[i].scores[assignmentNum] = newGrade;
}
}
}
Without more code to see what you have done one can only guess at what to do.
I thinking that your for loop should be based on "numStudents" not "numScores". The when the if statement finds a match and if you have put the scores into an array then you would need another for loop to find which element matches what you need to change. Unless "assignmentNum" is already the needed index for the array.
For now that is only a guess because I do not know what you have done with the rest of the program.