# Module 3. Constructors and Destructors Exercises

```1.  Create the ZooAnimal constructor function.  The function has 4
parameters -- a character string followed by three integer parameters.
In the constructor function dynamically allocate the name field (20
characters), copy the character string parameter into the name field,
and then assign the three integer parameters to cageNumber,
weightDate, and weight respectively.

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);
};

2.  Modify the function header below for the constructor function for
ZooAnimal.  Provide default values of "Nameless" for who, 9999 for
whichCage, 101 (January 1) for weighDay, and 100 for pounds.

// ---------- the constructor function
ZooAnimal::ZooAnimal (char* who, int whichCage, int weighDay, int pounds)
{
char *name = new char[20];
strcpy (name, who);
cageNumber = whichCage;
weightDate = weighDay;
weight = pounds;
}

3.  Write a ZooAnimal member conversion function that converts a type
ZooAnimal to produce a value of type int.  The function should simply
return the cageNumber data member.

class ZooAnimal
{
private:
char *name;
int cageNumber;
int weightDate;
int weight;
public:
ZooAnimal (char*, int, int, int); // constructor function
operator int (); // member conversion function
inline ~ZooAnimal () {}; // destructor function
void changeWeight (int pounds);
char* reptName ();
int reptWeight ();
int daysSinceLastWeighed (int today);
};
```