Code:
>Animal::Animal()
>{
> animalAge = 0;
> len = 7;
//Need room for the string terminator. Should be:
len = 8;
> animalName = new char[7];
//Should be:
animalName = new char[8];
> strcpy(animalName, "No Name");
> strcpy(animalSound, "No Sound");
> animalSound[15] = '\0';
//Don't need above line, but if it's there should be:
animalSound[14] = '\0';
> animalWeight = 0.0;
> numStrings++; // adds 1 to object count
> cout << numStrings << ": \"" << animalName
> << "\" default object created\n";
>}
>// 2) Defined Constructor
>Animal::Animal(int a, const char *name, const char *sound, >double d)
>{
> animalAge = a;
> len = strlen(name);
> animalName = new char[len + 1];
> strcpy(animalName, name);
> strncpy(animalSound, sound, 15);
> animalSound[15] = '\0';
//Either change to 14 or use:
strcpy(animalSound, sound);
//And leave out the next line.