CPS 100, Fall 2002, Sep 5 Inclass

Students Reprised

In the new students.h a class Eater is declared. The implementation is in students.cpp. The new client code is in school.cpp.

  1. In the header file students.h The line class Student; appears before the declaration of the class Eater? If this line is removed, the error message printed when the code is compiled is shown below, why is this error generated? (Note: line 32 is the declaration of the method Eater::doEat).
    
      students.h:32: `Student' was not declared in this scope
      students.h:32: `s' was not declared in this scope
    
    
    

  2. In the original version of Student::eat the code myEnergy += 5 was used. In the new version of Eater::doEat the code below is used. void Eater::doEat(Student * s) const // post: Student s has energy level changed, // message printed { cout << getMessage() << endl; s->changeEnergy(myEnergy); } Why isn't myEnergy += 5 used in this code?

  3. In the new declaration of DukeStudent in school.cpp there is a private class Chick declared. Why is this class private? What alternatives are there for where the class is declared?
    
    
    
    
  4. In the first version of school.cpp the output for a Duke student is as follows, note that both chick fil-a and pizza are eaten:
      Duke Chris: energy = 100
      chick fil' a-gain!!
      Pizza! yum yum, glurp, gobble, burp
      study study ... panic ... study
      Zzzzzzzzzzzzz, resting sleep
      work hard/play hard
    
    
    In the new version, pizza isn't eaten, only Chick fil-a. What code should be modified so that both kinds of food will be "eaten", and what are the modifications?
    
    
    
    
    
    
    
    
  5. Suppose UNC students are like Students, but they only lose 10 energy units when studying. What does the declaration for the class UNCStudent look like? What is the definition for a variable representing a UNC student named Bud who eats Cosmic Cantina Burritos?

Susan Rodger
Last modified: Wed Sep 4 22:04:58 EDT 2002