Lines 44–54 of Fig. 3.7 define the main
function that tests class GradeBook
and demonstrates initializing GradeBook
objects using a constructor. Line 47 creates and initializes GradeBook
object gradeBook1
. When this line executes, the GradeBook
constructor (lines 14–18) is called with the argument "CS101 Introduction to C++ Programming"
to initialize gradeBook1
’s course name. Line 48 repeats this process for GradeBook
object gradeBook2
, this time passing the argument "CS102 Data Structures in C++"
to initialize gradeBook2
’s course name. Lines 51–52 use each object’s getCourseName
member function to obtain the course names and show that they were indeed initialized when the objects were created. The output confirms that each GradeBook
object maintains its own data member courseName
.