would someone be willing to code this for me?
implement class tree on the right
make 2 generic types t1 and t2
minimum property requirements are listed on diagram.
each class should define
(1) get method for every property
2 set method for every property
3 display method that prints the name and current value of all its properties and all of its ancestor classes
assume all properties are private
each class should define the standard argument creature plant and animal
should also define comprehensive constructor.
put all code in one file
but separate class implementation and definition
below class code above main create max min and function each with three parameters
inside main create one object for each constructor
then call possible methods from every object
at the end call max with the age of one creature one animal and one plant
call min with bodytemps of two animals and a literal.
//Template class definition and implementation are present in the header file
// creature.h
#ifndef CREATURE_H_
#define CREATURE_H_
#include <iostream>
using namespace std;
template <class T1,class T2>
class Creature
{
T1 age;
T2 name;
public:
Creature(T1 age, T2 name);
void setAge(T1 age);
void setName(T2 name);
T1 getAge() const;
T2 getName() const;
void display() const;
};
template <class T1, class T2>
Creature<T1,T2>::Creature(T1 age, T2 name)
{
this->age = age;
this->name = name;
}
template <class T1, class T2>
void Creature<T1,T2>::setAge(T1 age)
{
this->age = age;
}
template <class T1, class T2>
void Creature<T1,T2>::setName(T2 name)
{
this->name = name;
}
template <class T1, class T2>
T1 Creature<T1,T2>::getAge() const
{
return age;
}
template <class T1, class T2>
T2 Creature<T1,T2>::getName() const
{
return name;
}
template <class T1, class T2>
void Creature<T1,T2>::display() const
{
cout<<"Name : "<<name<<endl;
cout<<"Age : "<<age<<endl;
}
#endif /* CREATURE_H_ */
//end of creature.h
// animal.h
#ifndef ANIMAL_H_
#define ANIMAL_H_
#include "creature.h"
template <class T1, class T2>
class Animal : public Creature<T1,T2>
{
T1 body_temp;
public:
Animal(T1 age, T2 name, T1 body_temp);
void setBodyTemp(T1 body_temp);
T1 getBodyTemp() const;
void display() const;
};
template <class T1, class T2>
Animal<T1,T2>::Animal(T1 age, T2 name, T1 body_temp) : Creature<T1,T2>(age,name) , body_temp(body_temp)
{}
template <class T1, class T2>
void Animal<T1,T2>::setBodyTemp(T1 body_temp)
{
this->body_temp = body_temp;
}
template <class T1, class T2>
T1 Animal<T1,T2>::getBodyTemp() const
{
return body_temp;
}
template <class T1, class T2>
void Animal<T1,T2>::display() const
{
Creature<T1,T2>::display();
cout<<"Body temperature : "<<body_temp<<endl;
}
#endif /* ANIMAL_H_ */
//end of animal.h
// plant.h
#ifndef PLANT_H_
#define PLANT_H_
#include "creature.h"
template <class T1, class T2>
class Plant : public Creature<T1,T2>
{
T1 sunAbsorb;
public:
Plant(T1 age, T2 name, T1 sunAbsorb);
void setSubAbsorb(T1 sunAbsorb);
T1 getSunAbsorb() const;
void display() const;
};
template <class T1, class T2>
Plant<T1,T2>::Plant(T1 age, T2 name, T1 sunAbsorb) : Creature<T1,T2>(age,name) , sunAbsorb(sunAbsorb)
{}
template <class T1, class T2>
void Plant<T1,T2>::setSubAbsorb(T1 sunAbsorb)
{
this->sunAbsorb = sunAbsorb;
}
template <class T1, class T2>
T1 Plant<T1,T2>::getSunAbsorb() const
{
return sunAbsorb;
}
template <class T1, class T2>
void Plant<T1,T2>::display() const
{
Creature<T1,T2>::display();
cout<<"Sun Absorb : "<<sunAbsorb<<endl;
}
#endif /* PLANT_H_ */
//end of plant.h
// main.cpp : C++ program to test the above classes
#include "creature.h"
#include "animal.h"
#include "plant.h"
#include <iostream>
using namespace std;
template <class T>
void max(T x, T y, T z)
{
T max_val = x;
if(max_val < y)
max_val = y;
if(max_val < z)
max_val = z;
cout<<"Maximum value : "<<max_val<<endl;
}
template <class T>
void min(T x, T y, T z)
{
T min_val = x;
if(min_val > y)
min_val = y;
if(min_val > z)
min_val = z;
cout<<"Maximum value : "<<min_val<<endl;
}
int main()
{
Creature<int,string> creature(10,"creature");
Animal<int,string> animal1(15,"animal1",35);
Animal<int,string> animal2(7,"animal2",25);
Plant<int,string> plant(13,"plant",45);
cout<<"Creature : "<<endl;
creature.display();
cout<<endl<<"Animal 1 : "<<endl;
animal1.display();
cout<<endl<<"Animal 2 : "<<endl;
animal2.display();
cout<<endl<<"Plant : "<<endl;
plant.display();
cout<<endl;
max(creature.getAge(),animal1.getAge(),plant.getAge());
min(animal1.getBodyTemp(),animal2.getBodyTemp(),5);
return 0;
}
//end of main.cpp
Output:
would someone be willing to code this for me? implement class tree on the right make 2 generic types t1 and t2 minimum property requirements are listed on diagram. each class should define (1) get met...