Question: In C++, complete: Previous animal, vegie and hunter classes (without mains): animal.h file: #ifndef ANIMAL_H #define ANIMAL_H #include class animal { protected: std::string name ;

In C++, complete:

In C++, complete: Previous animal, vegie and hunter classes (without mains): animal.h

Previous animal, vegie and hunter classes (without mains):

animal.h file:

#ifndef ANIMAL_H

#define ANIMAL_H

#include

class animal {

protected:

std::string name ; // the animal's name

static int count;

int animalID ; // the animal's unique ID

int volume ; // the volume of the animal's body

public:

animal();

animal(std::string n, int v) ; // creates an animal with name n and body volume v.

// animals are allocated a unique ID on creation

void set_name(std::string n);

void set_volume(int v);

virtual std::string get_name() = 0;

int get_animalID();

int get_volume();

};

#endif

animal.cpp file:

#include "animal.h"

#include

int animal::count =1;

animal::animal(){

name ="?";

volume = 0;

}

animal::animal(std::string n, int v) {

name=n;

animalID=count;

count++;

volume=v;

}

void animal::set_name(std::string n){

name=n;

}

void animal::set_volume(int v){

volume=v;

}

// virtual std::string get_name() = 0;

int animal::get_animalID(){

return animalID;

}

int animal::get_volume(){

return volume;

}

hunter.h file:

#ifndef HUNTER_H

#define HUNTER_H

#include

#include "animal.h"

class hunter : public animal {

int kills ; // how many kills have been recorded, initialised to 0

static int nextID ;

static int count;

public:

hunter(std::string n, int v);

std::string get_name();

void set_kills(int number_of_kills);

int get_kills();

};

#endif

hunter.cpp file:

#include

#include "hunter.h"

#include "animal.h"

int hunter::nextID = 1000;

int hunter::count = 0;

hunter::hunter(std::string n, int v) : animal(n, v){

volume = v;

name = n;

nextID++;

kills = count;

// kills =0;

// std::cout

}

std::string hunter::get_name(){

name.insert(0, "Hunter: ");

return name;

}

void hunter::set_kills(int number_of_kills){

// kills =0;

kills = number_of_kills;

// std::cout

}

int hunter::get_kills(){

return kills;

}

vegie.h file:

#ifndef vegie_h

#define vegie_h

#include "animal.h"

class vegie : public animal {

std::string favourite_food ; // the vegie's favourite food, initialise to "grass"

static int nextID ;

static std::string food ;

public:

vegie(std::string n,int v); // create a vegie with name n and body volume v

void set_favourite_food(std::string fav);

std::string get_favourite_food();

std::string get_name();

};

#endif

vegie.cpp file:

#include

#include "vegie.h"

#include "animal.h"

int vegie::nextID = 100;

std::string vegie::food = "grass";

vegie::vegie(std::string n,int v) : animal(n,v){

name = n;

volume = v;

nextID++;

favourite_food = food;

}

std::string vegie::get_favourite_food(){

name.insert(0, "Safe: ");

return favourite_food;

}

void vegie::set_favourite_food(std::string fav){

favourite_food = fav;

}

std::string vegie::get_name(){

return name;

}

3-1 Define and implement a class named zoo. A zoo object represents a collection of animal objects. The zoo class has the following constructor and private attibutes zoo(string n,int cows,int lions); // create a zoo with the given number of cows and lions // the zoo's name //the number of animals in the zoo string name int number.of animals animal animals // the zoo's animals A cow is represented by a vegie object, all cows are named "Daisy" and have volume 100. A lion is represented by a hunter object, all lions are named "Clarence" and have volume 50. The vegie objects must come before the hunter objects in the array animals. You need get functions to access the private attributes, name, number of_animals and animals, but there must not be any set functions for these private attributes

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!