Constructor

The class’s constructor (declared in line 15 of Fig. 7.15 and defined in lines 10–14 of Fig. 7.16) has two parameters—the course name and a reference to an array of grades. When a program creates a GradeBook object (e.g., line 15 of Fig. 7.17), the program passes an existing int array to the constructor, which copies the array’s values into the data member grades (line 12 of Fig. 7.16). The grade values in the passed array could have been input from a user or read from a file on disk (as we discuss in Chapter 14, File Processing). In our test program, we simply initialize an array with a set of grade values (Fig. 7.17, lines 11–12). Once the grades are stored in data member grades of class GradeBook, all the class’s member functions ...

Get C++11 for Programmers, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.