Write in C Write a program to create a hierarchy of dinosaur
Write in C++
Write a program to create a hierarchy of dinosaur species. Each species is represented by a class, as described below. A parent dinosaur class CDinosaur Has a name, weight w and age a A user can construct a dinosaur with a given name, weight and age A user can get and set each of name, weight and age A user can compute strength s(w, a) (abstract function) A child carnivore class CCarnivore derived from parent CDinosaur A user can construct a carnivore with a given name, weight and age A user can compute strength s(w, a) = w - (a^2+1) A child herbivore class CHerbivore derived from parent CDinosaur Has an intelligence i A user can construct a herbivore with a given name, weight, age and intelligence A user can get and set the intelligence A user can compute strength s(w, a) = wlog_10(l+a) A user can compute evasion e(s, i) = 0.5si A child terrestrial carnivore class CTerrestrial derived from parent CCarnivore Has a bite force b A user can construct a terrestrial carnivore with a given name, weight, age and bite force A user can get and set the bite force A user can compute power p(s, b) = se^b A child aerial carnivore class CAerial derived from parent CCarnivore A user can construct an aerial carnivore with a given name, weight and age A user can compute velocity v(s) = s^2 Your submission should include a screenshot of the program using the following script. Construct a carnivore c1 with name, weight and age as \"Allosaurus\", 3000 and 2, respectively Set age of c1 to 5 Compute and print strength of c1 Construct a herbivore h1 with name, weight, age and intelligence as \"Triceratops\", 12000, 13 and 0.35, respectively Set weight of h1 to 13000 Set intelligence of h1 to 0.375 Compute and print strength of h1 Compute and print evasion of h1 Construct a terrestrial carnivore c2 with name, weight, age and bite force as \"Tyrannosaurus Rex\", 5000, 4 and 0.9, respectively Set age of c2 to 10 Set weight of c2 to 7500 Compute and print strength of c2 Compute and print power of c2 Construct an aerial carnivore c3 with name, weight and age as \"Quetzalcoatlus\", 500 and 20, respectively Compute and print strength of c3 Compute and print velocity of c3Solution
#include <iostream>
#include <cmath>
using namespace std;
class CDinosaur //Loan base class
{
private:
string name;
double weight;
int age;
public:
/* Parameterized Constructor */
CDinosaur(string name,double weight,int age)
{
this->name=name;
this->weight=weight;
this->age=age;
}
string getName() {
return name;
}
void setName(string name) {
this->name = name;
}
double getWeight() {
return weight;
}
void setWeight(double weight) {
this->weight = weight;
}
int getAge() {
return age;
}
void setAge(int age) {
this->age = age;
}
virtual double strength(double weight,int age);
};
class CCarnivore : CDinosaur //Derived class from loan
{
public:
/* Parameterized Constructor */
CCarnivore(string name,double weight,int age)
{
CCarnivore:CDinosaur(name,weight,age);
}
virtual double strength(double weight,int age)
{
double strength=0.0;
strength=weight-(pow(age,2)+1);
return strength;
}
};
class CHerbivore: CDinosaur
{
private:
double intelligence;
public:
/* Parameterized Constructor */
CHerbivore(string name,double weight,int age,double intelligence)
{
CHerbivore: CDinosaur(name,weight,age);
this->intelligence=intelligence;
}
int getIntelligence() {
return intelligence;
}
void setIntelligence(double intelligence) {
this->intelligence = intelligence;
}
virtual double strength(double weight,int age)
{
double strength=0.0;
strength=weight*log10(1+age);
return strength;
}
double evasion(double strength,double intelligence)
{
return 0.5*strength*intelligence;
}
};
class CTerrestrail: CCarnivore
{
private:
double biteforce;
public:
/* Parameterized Constructor */
CTerrestrail(string name,double weight,int age,double biteforce)
{
CTerrestrail: CCarnivore(name,weight,age);
this->biteforce=biteforce;
}
int getBiteForce() {
return biteforce;
}
void setBiteForce(double biteforce) {
this->biteforce = biteforce;
}
double power(double strength,double biteforce)
{
return strength*exp(biteforce);
}
};
class CAerial: CCarnivore
{
public:
/* Parameterized Constructor */
CAerial(string name,double weight,int age)
{
CAerial: CCarnivore(name,weight,age);
}
double velocity(double strength)
{
return strength*strength;
}
};
int main()
{
CCarnivore c1(\"Allosaurus\",3000,2);
c1.setAge(5);
cout<<\"Strength of \"<<c1.getName()<<\":\"<<c1.strength(3000,2);
CHerbivore h1(\"Triceratops\",12000,13,0.35);
h1.setWeight(13000);
h1.setIntelligence(0.375);
cout<<\"Strength of \"<<h1.getName()<<\":\"<<h1.strength(12000,13);
cout<<\"Evasion of \"<<h1.getName()<<\":\"<<<<h1.evasion(h1.strength(12000,13),h1.getIntelligence());
CTerrestrail c2(\"Tyannosaurus Rex\",5000,4,0.9);
c2.setAge(10);
c2.setWeight(7500);
cout<<\"Strength of \"<<c2.getName()<<\":\"<<c2.strength(5000,4);
cout<<\"Power of \"<<c2.getName()<<\":\"<<c2.power(c2.strength(5000,4),0.9);
CAerial c3(\"Quetzolcoatlus\",500,20);
cout<<\"Strength of \"<<c3.getName()<<\" :\"<<c3.strength(500,20);
cout<<\"Velocity of \"<<c3.getName()<<\" :\"<<c3.velocity(c3.strength(500,20));
}


