... Alternate View

 1   // Fig. 4.6: Student.h
 2   // Student class that stores a student name and average.
 3   #include <string>
 4
 5   class Student {
 6   public:
 7       // constructor initializes data members
 8       Student(std::string studentName, int studentAverage)
 9          : name(studentName) {
10
11          // sets average data member if studentAverage is valid
12          setAverage(studentAverage);
13       }
14
15       // sets the Student's name
16       void setName(std::string studentName) {
17          name = studentName;
18       }
19
20       // retrieves the Student's name
21       std::string getName() const {
22          return name;
23       }
24
25       // sets the Student's average
26       void setAverage(int studentAverage) {
27          // validate that studentAverage is > 0 and <= 100; otherwise,
28          // keep data member average's current value
29          if

Get C++ How to Program, 10/e now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.