11.07.2015 Views

tYSR20

tYSR20

tYSR20

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 15: Protecting Members: Do Not Disturb 203The remaining members of Student can be declared protected to keep otherfunctions’ prying expressions out of Student’s business.class Student{public:// grade - return the current grade point averagefloat grade(){return gpa;}// hours - return the number of semester hoursint hours(){return semesterHours;}// addCourse - add another course to the student’s recordfloat addCourse(int hours, float grade);// the following members are off-limits to othersprotected:int semesterHours; // hours earned toward graduationfloat gpa;// grade point average};Now the members semester hours and gpa are accessible only to othermembers of Student. Thus, the following doesn’t work:Student s;int main(int argcs, char* pArgs[]){// raise my grade (don’t make it too high; otherwise, no// one would believe it)s.gpa = 3.5;//

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!