It looks to me like you will get an out of scope error here (and other places):
void role::setGrade(int studentId, char grade) {
for (int x=0; x < numStudents; x++)
if (courseRole[x].getId() == studentId) break;
if (x < numStudents)
courseGrade[x] = grade;
}
Putting brackets in, this is equivalent to the above:
void role::setGrade(int studentId, char grade)
{
for (int x=0; x < numStudents; x++) // x is in scope inside the for loop
{
if (courseRole[x].getId() == studentId)
{
break;
}
}
// x goes out of scope here. "Binding" is now obsolete.
if (x < numStudents)
{
courseGrade[x] = grade;
}
} Do you want this:
if (x < numStudents)
{
courseGrade[x] = grade;
}
as part of your "for" loop? Currently the code directly above is not inside the for loop. x is meaningless outside of this loop. That is why you are getting that error. If the directly above code is part of the for loop, change it to this and it will not go out of scope:
void role::setGrade(int studentId, char grade)
{
for (int x=0; x < numStudents; x++) // x is in scope inside the for loop
{
if (courseRole[x].getId() == studentId)
{
break;
}
// x is still in scope
if (x < numStudents)
{
courseGrade[x] = grade;
}
}
// x goes out of scope here.
}