home *** CD-ROM | disk | FTP | other *** search
/ C++ for Dummies (3rd Edition) / C_FD.iso / CHAP09 / STUDENT.H < prev   
C/C++ Source or Header  |  1996-09-02  |  788b  |  36 lines

  1. class Student
  2. {
  3.   public:
  4.    //grade - return the current grade point average
  5.    float grade()
  6.    {
  7.       return gpa;
  8.    }
  9.    //hours - return the number of semester hours
  10.    int hours() 
  11.    {
  12.       return semesterHours;
  13.    }
  14.  
  15.    //addCourse - add another course to the studentÆs record
  16.    float addCourse(int hours, float grade);
  17.  
  18.    //here we allow the grade to be changed
  19.    float grade(float newGPA)
  20.    {
  21.       float oldGPA = gpa;
  22.       //only if the new value is valid
  23.       if (newGPA > 0 && newGPA <= 4.0)
  24.  
  25.       {
  26.          gpa = newGPA;
  27.       }
  28.       return oldGPA;
  29.    }
  30.  
  31.   //the following members are off-limits to others
  32.   protected:
  33.    int   semesterHours;  //hours earned towards graduation
  34.    float gpa;            //grade point average
  35. };
  36.