c++ Zookeeper Leona Grande has the opportunity to add more animals to her zoo. S
ID: 3778182 • Letter: C
Question
c++
Zookeeper Leona Grande has the opportunity to add more animals to her zoo. She needs your help to determine whether this is economically and humanely feasible. Using polymorphism, inheritance, and an abstract base class, write a header file that she can use to help make the decision.
The different kinds of animals and necessary information for each are below:
I. Feeding frequency:
I.Feeding frequency (cont):
II.Feeding amount:
III. Veterinary cost (yearly):
Age: 0-12 - $200
13-96- $100
>96- $500
Weight: <= 0.5 - $100
>0.5 -$250
Given the information above, write the following class member functions:
1) display
- To display the name of the animal, the type of the animal, and the food the animal eats.
2) calcFoodAmt
- To return the amount of food the animal will consume in a year.
3) calcVetCost
- To return the veterinary costs associated with a particular animal.
Remember, these functions should be tested keeping polymorphism in mind. In other words, your testing should exercise these functions by binding a pointer/reference of base object type to an object of a derived type, not just by using an object of the derived class!
NOTE:
Arguments for the constructors should be passed in the following order:
Mammal: name, food, age, weight
Bird: name, food, weight
Fish:name, food, length
Reptile: name, food
Amphibian: name, food
//
//
//
//need to follow the template below
Mammal: Bird: Fish: Reptile: Amphibian: - Name - Name - Name - Name - Name - Food - Food - Food - Food - Food - Age (months) - Weight (lbs) Length (cm) - Weight (lbs)Explanation / Answer
#include <string.h>
class Animal
{
sring name,food;
float tot_food;
int vet_cost;
Animal(string name,string food)
{
this.name=name;
this.food=food;
}
void display( string type)
{
cout<<"Name of the animal is: "<<name;
cout<<name<<" is "<<type;
cout<<"food eaten by "<<name<<"is "<<food;
}
float calcFoodAmt()
{
return tot_food;
}
int totVetCost()
{
return vet_cost;
};
class Mammal:public Animal
{
int age,weight;
Mammal(String name,String food, int age, float weight)
{
Animal(name,food);
this.age=age;
this.weight=weight;
if(age<=12)
tot_food=(5*365*(weight/5));
else if(age>12 &&age<=24)
tot_food=(4*365*(weight/5));
else
tot_food=(3*365*(weight/5));
if(age<=12)
vet_cost=200;
else if(age<=96)
vet_cost=100;
else
vet_cost=500;
}
};
class Fish:public Animal
{
int length;
Fish(String name,String food, int length)
{
Animal(name,food);
this.length=length;
if(length<=30)
tot_food=2*365*1.5;
else
tot_food=365*1.5;
vet_cost=0;
}
};
class Bird:public Animal
{
float weight;
Bird(String name,String food,float weight)
{
Animal(name,food);
this.age=age;
this.weight=weight;
if(weight<=0.5)
tot_food=(3*365*(0.5*weight));
else
tot_food=(2*365*(0.5*weight));
if(weight<=0.5)
vet_cost=100;
else
vet_cost=250;
}
};
class Amphibian:public Animal
{
Amphibian(string name,string food)
{
Animal(name,food);
vet_cost=0;
tot_food=0.5*365;
}
};
class Reptile:public Animal
{
Reptile(string name,string food)
{
Animal(name,food);
tot_food=52*2;
vet_cost=175;
}
};
int main()
{
Animal a;
string name,food;
int length,age;
float weight;
int ch;
string type;
cout<<"select the type of animal you need to give";
cot<<"1:mammel";
cout<<"2:bird";
cout<<"3:reptile";
cout<<"4:fish";
cout<<"5:amphibian";
cin<<ch;
while(ch>=1&&ch<=5){
if(ch==1)
{
type="mammel"
cout<<"please enter name,food,age in months and weight ";
cin>>name>>food>>age>>weight;
a=new Mammel(name,food,age,weight);
}
else if(ch==2)
{
type="bird"
cout<<"please enter name,food, and weight ";
cin>>name>>food>>weight;
a=new Bird(name,food,weight);
}
else if(ch==3)
{
type="reptile"
cout<<"please enter name,food ";
cin>>name>>food;
a=new Reptile(name,food);
}
else if(ch==4)
{
type="fish"
cout<<"please enter name,food,age in months and length ";
cin>>name>>food>>lenght;
a=new Fish(name,food,lenght);
}
if(ch==5)
{
type="amphibian"
cout<<"please enter name,food ";
cin>>name>>food>>;
a=new Amphibian(name,food);
}
a.display(type);
cout<<the total amount of food required is <<a.calFoodamt()<<"lb";
cout<<"the total veternity cost is "<<a.totVetCost()<<"$";
}
if(ch<=0&&ch>5)
cout<<"invalid choice";
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.