Class inheritance and polymorphism: Predator-Prey Simulation. Simulation: - In a world of 20 x 20 grid of cells, there lives two kinds of animals: ant and bug. - Each ant/bug takes on cell. - Bugs eat...

1 answer below »

Class inheritance and polymorphism: Predator-Prey Simulation.  Simulation: - In a world of 20 x 20 grid of cells, there lives two kinds of animals: ant and bug.  - Each ant/bug takes on cell.  - Bugs eat ants for food.  - Time is simulated in time steps.  - Each animal performs some action every time step.  - During one time step, all bugs should move before the ants do.  - Initially, the grid has 5 bugs and 100 ants.  - Print the grid after each step. Use 'x' to represent bug and 'o' to represent ant.  - Prompt user to press Enter to move to the next step. To exit: ctrl + c   Requirement: - Create a base class: Animal.  - Derive a class: Ant, as the prey.  - Derive a class: Bug, as the predator.   Class Ant:  - Move: every time step, randomly try to move up, down, left, or right. If the neighboring cell in the selected direction is occupied or would move the ant off the grid, then the ant stays in the current cell.  - Breed: if an ant survives for three times steps, then at the end of the time step(that is, after moving) the ant will breed. This is simulated by creating a new ant in an adjacent cell that is empty. If there is not empty cell available, then no breeding occurs. Once an offspring is produces, the parent ant needs to wait three more time steps for next breed.   Class Bug:  - Move: if there is an adjacent ant (up, down, left, right) the the bug will move to that cell and eat the ant. Otherwise, the bug wil move according to the same rule as the ant. Bugs only eat ants.  - Breed: if a bug survives for eight time steps, then at the end of the time step it will spawn off a new bug in the same manner as the ant.  - Starve: if a bug has not eaten an ant within the last three time steps, then at the end of the third time step it will starve and die. The bug should then be removed from the grid of cells.   File structures and names: - animal.h, animal.cpp, ant.h, ant.cpp, bug.h, bug.cpp, sim.h, sim.cpp - makefile: contains compile instructions for make.   Grading:  - compilable and meaningfull attemps - classes - simulation - comment, indentation and file names and makefile


Answered Same DayApr 22, 2021

Answer To: Class inheritance and polymorphism: Predator-Prey Simulation. Simulation: - In a world of 20 x 20...

Aditi answered on Apr 25 2021
134 Votes
Solution/animal.cpp
Solution/animal.cpp
#include "animal.h"
#include 
using namespace std;
an
imal :: animal(string n, int c, int s){
    name = n;
    count = c;
    starveCount = s;
}
string animal :: getName(){
    return name;
}
void animal :: setName(string n){
    name = n;
}
void animal :: addCount(int c){
    count += c;
}
int animal :: getCount(){
    return count;
}
void animal :: setCount(int c){
    count = c;
}
int animal :: getStarveCount(){
    return starveCount;
}
void animal :: setStarveCount(int s){
    starveCount = s;
}
void animal :: addStarveCount(int s){
    starveCount += s;
}
Solution/animal.h
#ifndef ANIMAL_H
#define ANIMAL_H
#include
using namespace std;
class animal{
    private:
        string name;
        int count;
        int starveCount;
    
    public:
        animal(string, int, int);
        string getName();
        void setName(string n);
        int getCount();
        void addCount(int);
        void setCount(int);
        int getStarveCount();
        void setStarveCount(int s);
        void addStarveCount(int...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here