Enhancing GradeBook Validation

Let’s consider an enhancement we made to class GradeBook. In Fig. 3.16, our setCourseName member function validated the course name by testing whether the course name’s length was less than or equal to 25 characters, using an if statement. If this was true, the course name would be set. This code was followed by an if statement that tested whether the course name’s length was larger than 25 characters (in which case the course name would be shortened). The second if statement’s condition is the exact opposite of the first if statement’s condition. If one condition evaluates to true, the other must evaluate to false. Such a situation is ideal for an if...else statement, so we’ve modified our code, replacing the two ...

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.