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

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