CS177/457 C++ Programming
Spring 1998

Feeding time: Dynamic allocation and virtual functions

Introduction

Your program will print out a feeding schedule for all the animals in the zoo. Different kinds of animals have different feeding requirements--type of food, amount of food and how it is to be delivered.

Requirements

There are three kinds of animals in our zoo: mammals, reptiles and birds. In the mammals, we have two tigers, Kuma, and Aralta; a donkey, Phil, and a panda LimLim. Amongst the reptiles we have an anaconda called Fred, two iguanas, Charles and Diana, and a crocodile called Sugar. The birds don't have names, but numbers: six lesser crested thrushes, numbers 4725 through 4730, a horn-billed parrot, number 2122, and ten north American starlings, numbers 3010 through 3019. It's a small zoo!

The feeding requirements are in the table below:

Animal

Type of food

Amount

Delivery

tiger

beef

10 pounds

remote

donkey

hay

5 pounds

pen

panda

bamboo leaves

20 pounds

remote

anaconda

live rat

1

cage

iguana

crickets

25

cage

crocodile

dead rat

6

remote

thrush

seeds

2 ounces

pen

parrot

seeds

4 ounces

hand

starling

live bugs

1 ounce

cage

Your program should be able to add new animals, store the information in a database and print feeding requirements of all the animals in the zoo.

Hints and notes

Deliverables

  1. Source code showing classes for Animal, each of the kinds listed in the table, and several in an intermediate layer. Each class has one public function (apart from its constructor): printFeedingRequirements, which MUST be virtual in class Animal. The main function makes the zoo, adds the animals and feeds them:
  2. int main() {
    vector<Animal*> zoo;

    zoo.push_back(new Donkey("Phil"));
    zoo.push_back(new Anaconda("Fred"));

    for (int animal = 0; animal < zoo.size(); animal++)
    zoo[animal]->printFeedingRequirements();
    }

  3. Output that states the feeding requiremens for each animal in the zoo.

Due Date

Friday 24th. April at 5 pm.