The main
function (lines 38–54) creates one object of class GradeBook
and uses each of its member functions. Line 41 creates a GradeBook
object named myGradeBook
. Lines 44–45 display the initial course name by calling the object’s getCourseName
member function. The first line of the output does not show a course name, because the object’s courseName
data member (i.e., a string
) is initially empty—by default, the initial value of a string
is the so-called empty string, i.e., a string that does not contain any characters. Nothing appears on the screen when an empty string is displayed.
Line 48 prompts the user to enter a course name. Local string
variable nameOfCourse
(declared in line 40) is set to the course name entered by the user, which is obtained by the call to the getline
function (line 49). Line 50 calls object myGradeBook
’s setCourseName
member function and supplies nameOfCourse
as the function’s argument. When the function is called, the argument’s value is copied to parameter name
(line 14) of member function setCourseName
. Then the parameter’s value is assigned to data member courseName
(line 16). Line 52 skips a line; then line 53 calls object myGradeBook
’s displayMessage
member function to display the welcome message containing the course name.
3.142.171.180