c++ Zookeeper Leona Grande has the opportunity to add more animals to her zoo. S
ID: 3837081 • 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<bits/stdc++.h>
using namespace std;
class Animal {
protected:
string m_name;
string m_food;
public:
Animal(){
m_name = "";
m_food = "";
}
Animal(string name, string food){
m_name = name;
m_food = food;
}
virtual void display() = 0;
virtual float calcFoodAmt() = 0;
virtual float calcVetCost() = 0;
};
class Mammal : public Animal {
protected:
int m_age;
float m_weight;
public:
Mammal(string name,string food,int age,float weight) : Animal(name,food){
m_age = age;
m_weight = weight;
}
void display(){
cout<<m_name<<endl;
cout<<"Mammal"<<endl;
cout<<m_food<<endl;
}
float calcFoodAmt(){
int fed_freq;
if(m_age >=0 && m_age <= 12)
fed_freq = 5;
else if(m_age >=13 && m_age <= 24)
fed_freq = 4;
else
fed_freq = 3;
float fed_amt;
fed_amt = ceil(m_weight/5);
float foodAmt;
foodAmt = fed_freq*fed_amt*365;
return foodAmt;
}
float calcVetCost(){
float cost;
if(m_age <= 12)
cost = 200;
else if(m_age >= 13 && m_age <= 96)
cost = 100;
else
cost = 500;
return cost;
}
};
class Bird : public Animal{
protected:
float m_weight;
public:
Bird(string name, string food, float weight) : Animal(name,food){
m_weight = weight;
}
void display(){
cout<<m_name<<endl;
cout<<"Bird"<<endl;
cout<<m_food<<endl;
}
float calcFoodAmt(){
int fed_freq;
if(m_weight <= 0.5)
fed_freq = 3;
else
fed_freq = 2;
float fed_amt;
fed_amt = m_weight*0.5;
float foodAmt;
foodAmt = fed_freq*fed_amt*365;
return foodAmt;
}
float calcVetCost(){
float cost;
if(m_weight <= 0.5)
cost = 100;
else
cost = 250;
return cost;
}
};
class Fish : public Animal{
protected:
float m_length;
public:
Fish(string name,string food,int length) : Animal(name, food){
m_length = length;
}
void display(){
cout<<m_name<<endl;
cout<<"Fish"<<endl;
cout<<m_food<<endl;
}
float calcFoodAmt(){
int fed_freq;
if(m_length<=30)
fed_freq = 2;
else
fed_freq = 1;
float fed_amt;
fed_amt = 1.5;
float foodAmt;
foodAmt = fed_freq*fed_amt*365;
return foodAmt;
}
float calcVetCost(){
float cost=0;
return cost;
}
};
class Reptile : public Animal{
public:
Reptile(string name,string food) : Animal(name,food){}
void display(){
cout<<m_name<<endl;
cout<<"Reptile"<<endl;
cout<<m_food<<endl;
}
float calcFoodAmt(){
int fed_freq;
fed_freq = 2;
float fed_amt;
fed_amt = 1;
float foodAmt;
foodAmt = fed_freq*fed_amt*ceil(365/7);
return foodAmt;
}
float calcVetCost(){
float cost = 175;
return cost;
}
};
class Amphibian : public Animal{
public:
Amphibian(string name,string food) : Animal(name,food){}
void display(){
cout<<m_name<<endl;
cout<<"Amphibian"<<endl;
cout<<m_food<<endl;
}
float calcFoodAmt(){
int fed_freq = 1;
float fed_amt = 0.5;
float foodAmt;
foodAmt = fed_freq*fed_amt*365;
return foodAmt;
}
float calcVetCost(){
float cost=0;
return cost;
}
};
int main(){
Animal *ptr;
Mammal mam("shdghs","sdhsd",12,23);
Bird brd("ajsdfhj","asdjfh",234);
Fish fsh("ajsd","hfsdj",98);
Reptile rep("jdfh","jsdhfj");
Amphibian amph("jasdas","ddj");
ptr = &mam;
ptr->display();
cout<<ptr->calcFoodAmt()<<endl;
cout<<ptr->calcVetCost()<<endl;
ptr = &brd;
ptr->display();
cout<<ptr->calcFoodAmt()<<endl;
cout<<ptr->calcVetCost()<<endl;
ptr = &fsh;
ptr->display();
cout<<ptr->calcFoodAmt()<<endl;
cout<<ptr->calcVetCost()<<endl;
ptr = &rep;
ptr->display();
cout<<ptr->calcFoodAmt()<<endl;
cout<<ptr->calcVetCost()<<endl;
ptr = &h;
ptr->display();
cout<<ptr->calcFoodAmt()<<endl;
cout<<ptr->calcVetCost()<<endl;
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.