Answered step by step
Verified Expert Solution
Question
1 Approved Answer
The code provided #include #include #include #include #include #include using namespace std; struct Animal { int x; int y; int age; int health; int id;
The code provided
#include#include #include #include #include #include using namespace std; struct Animal { int x; int y; int age; int health; int id; string gender; }; struct Environment { string climate; int num_foxes; int grid_size_x; int grid_size_y; Animal *foxes; }; int GetRandomBetween(int floor, int ceiling); Animal CreateAnimal(int min_age, int max_age, int id, int gridx, int gridy, string climate); string GetGender(); void GeneratePopulations(Environment& env); Environment GenerateEnvironment(); int GetHealth(string climate, int age, int grid_x, int grid_y, int x, int y); void PrintAnimals(Animal *animals, int size); int main() { srand (time(NULL)); Environment env = GenerateEnvironment(); GeneratePopulations(env); return 0; } int GetRandomBetween(int floor, int ceiling) { return floor + (rand() % static_cast (ceiling - floor + 1)); } Animal CreateAnimal(int max_age, int id, int gridx, int gridy, string climate) { Animal animal; animal.age = GetRandomBetween(1, max_age); animal.x = GetRandomBetween(0, gridx); animal.y = GetRandomBetween(0, gridy); animal.health = GetHealth(climate, animal.age, gridx, gridy, animal.x, animal.y); animal.id = id; animal.gender = GetGender(); return animal; } string GetGender() { int g = GetRandomBetween(0,10); if(g>5) return "f"; else return "m"; } void GeneratePopulations(Environment& env) { int max_age; pop_size: cout>env.num_foxes; if(cin.fail()==true || env.num_foxes>max_age; if(cin.fail()==true || max_age>env.climate; if(env.climate == " " || (env.climate !="temperate" && env.climate !="TEMPERATE" && env.climate !="Temperate" && env.climate !="Tundra" && env.climate !="tundra" && env.climate !="TUNDRA" && env.climate != "TROPICAL" && env.climate != "tropical" && env.climate !="Tropical" )){ cout>env.grid_size_x; if(env.grid_size_x>env.grid_size_y; if(env.grid_size_y=.8) //for tundra the extremes are in the far north so that's where lowest health will be return GetRandomBetween(1,4); else //rest is average health return GetRandomBetween(4, 7); } else if(climate == "temperate" || climate == "TEMPERATE") { //extremes are non-existent but older generations are not resilient and will always have good health if(age>5) return GetRandomBetween(1,4); else GetRandomBetween(4,7); } else if(climate == "tropical" || climate == "TROPICAL") { if(y/grid_y
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started