# C++ DairyAnimal Program - 66335

Solution Posted by

Rating : (19)A+
Solution Detail
Price: \$20.00
Request Description

Write a base class named DairyAnimal and two classes, Goat and Cow that inherit from it. You may use one file, or a multi-file project; whichever is easier for you.

1. Declare a DairyAnimal class?a. Write a base class named DairyAnimal that has the following data members:

float age;            //  years?            int weight;          // weight of animal in pounds? int food;               // food eaten each day in pounds

b. And the following functions:

DairyAnimal();                                  // set age to 1.0F, weight to 1000, and food to 0?DiaryAnimal(float a, int w);                // overloaded constructor lets you set age and weight?void feed(int f);                                 // pounds of food fed to the animal per day?float milk();                                        // gallons of milk produced per day =  weight / food?

c. Write two tests:  1) Display the amount of milk produced per day using an object created with the default constructor and 20 pounds of food.  2) Display the milk produced using an object created with the overloaded constructor and with age = 1, weight = 100 and lbsFood = 2.

2. Use inheritance to declare a Cow class

a. Override the milk function to use the following calculations:?If the age is 1 or more and 10 or less, gallons of milk = 0.5 * weight / food?Otherwise, gallons of milk = 0

d. Write tests for a: 1) 0.9 year old cow (any weight and amount of food. 2) 1 year old, 900 pound cow which is fed 15 pounds of food. 3) A 10 year old, 1100 pound cow, fed 25 pounds. 4) 10.1 year old cow (any weight and amount of food).

3. Use inheritance to declare a Goat class

a. This class will use DairyAnimal as a base class and inherit the public functions. Decide whether or not you will need to write new constructors.

b. Override the milk function to use the following calculations:?If the age is 0.7 or more and 10 or less, gallons of milk = weight / food?Otherwise, gallons of milk = 0.

Can you call the base class milk function?

c. Write the same four tests as for the Cow class, but use the following weights and amounts of food:

2) weight = 90 pounds, food = 1 pound

3) weight = 110 pounds, food = 2 pounds

Solution Description

Write a base class named DairyAnimal and two classes, Goat and Cow that inherit from it. You may use one file, or a multi-file project; whichever is easier for you.

1. Declare a DairyAnimal class?a. Write a base class named DairyAnimal that has the following data members:

float age;            //  years?            int weight;          // weight of animal in pounds<

Attachments