Module 4. Static Members, Friends Exercise Answers

1.
   class ZooAnimal  
   {
    private:
      char *name;
      int cageNumber;
      static int oldestWeightDate;
      int weightDate;
      int weight;
    public:
      ZooAnimal (char*, int, int, int); // constructor function
      void changeWeight (int pounds);
      static void changeOldestWeightDate (int date);
      char* reptName ();
      int reptWeight ();
      int daysSinceLastWeighed (int today);
   };

   int ZooAnimal::oldestWeightDate;  //define static member at global scope

   // -------- member function to modify the oldest weight date allowed
   // -------- if an animal's weightDate is older than this, the animal 
   // -------- should be re-weighed
   void ZooAnimal::changeOldestWeightDate (int date)
   {
    oldestWeightDate = date;
   }


2.
   // -------- function to return the oldest ZooAnimal weight date allowed
   // -------- if an animal's weightDate is older than this, the animal 
   // -------- should be re-weighed
   int reptOldestZooAnimalWeightDate ()
   {
    return ZooAnimal::oldestWeightDate;
   }


3.
   // -------- member function to return the typical nutrition value
   // -------- of the animal's meals
   float ZooAnimal::reptNutrition ()
   {
    return nutr.reptMealNutrition ();
   }


4.
   class ZooAnimal  
   {
    private:
      char *name;
      int cageNumber;
      int weightDate;
      int weight;
    public:
      ZooAnimal (char*, int, int, int); // constructor function
      ~ZooAnimal (); // destructor function
      void changeWeight (int pounds);
      char* reptName ();
      int reptWeight ();
      int daysSinceLastWeighed (int today);
      friend class cageAssignment;
   };


5.
   // -------- member function to move the animal to another cage
   void cageAssignment::changeCage (ZooAnimal& critter)
   {
    critter.cageNumber = enclosure++;
   }


6.
   class ZooAnimal  
   {
    private:
      char *name;
      int cageNumber;
      int weightDate;
      int weight;
    public:
      ZooAnimal (char*, int, int, int); // constructor function
      ~ZooAnimal (); // destructor function
      void changeWeight (int pounds);
      char* reptName ();
      int reptWeight ();
      int daysSinceLastWeighed (int today);
      friend int cageAssignment::reptCage (ZooAnimal&);
   };