The problem is in the
GradeBook
constructor.
GradeBook::GradeBook(string name)
{
setCourseName(name);
int aCount=0;
int bCount=0;
int cCount=0;
int dCount=0;
int fCount=0;
}
What is happening here is that you are not initializing the member variables of the
GradeBook
class but instead are creating local variables.
Here a read through this to explain the concept of
scope[
^].
Because the member variables are not initialized you get the 'weird' numbers in your output. When the program start to use them they have an undetermined start value.
To correctly initialize the member variables you need to remove the '
int
' from the statements in the constructor.
GradeBook::GradeBook(string name)
{
setCourseName(name);
aCount=0;
bCount=0;
cCount=0;
dCount=0;
fCount=0;
}
You can also use member initialization list
GradeBook::GradeBook(string name)
: aCount( 0 ),
bCount( 0 ),
cCount( 0 ),
dCount( 0 ),
fCount( 0 )
{
setCourseName(name);
}
Here is some information about the
initialization list[
^].