Answered step by step
Verified Expert Solution
Question
1 Approved Answer
C++ program. please answer with complete code and output. please add //comments on each step and make sure to complete all steps of the program.
C++ program. please answer with complete code and output. please add //comments on each step and make sure to complete all steps of the program. incomplete answers will be disliked. (pic is a bit blurry but you can read zoomed in)
ADDITION, please zoom in to read.
Polymorphism Organism Understand the Application The goal for this programming project is to create a simple 2D predator- prey simulation. In this simulation, the prey are ants and the predators are doodlebugs. These critters live in a 2020 grid of cells. Only one critter may occupy a cell at a time. The grid is endosed, so a critter is not allowed to move off the edges of the world. Time is simulated in steps Each critter performs some action every time step. The Program Spec Class Ants: The ants behave according to the following model Move. For every time step, the ants 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 time steps, at the end of the time step (ie, after moving the ant will breed. This is simulated by creating a new ant in an adjacent fup, down, left, or right) cel that is empty. there is no empty cell available, no breeding occurs. Once an offspring is produced, an ant cannot produce an offspring again until it has survived three more time steps Be sure to include a default constructor mutators, and accessors for all private member variables Class Doodlebugs: The doodlebugs behave according to the following model Move. For every time step, the doodlebug will move to andment cell containing an ant and eat the ant. If there are no ants in admin cells, the doodiebug moves according to the same rules as the ant Note that a doodlebug cannot eat other doodlebugs Breed. If a doodlebug survives for echt time steps, at the end of the time step it will spawn of a new doodlebuis in the same marinera Uvant Starve. If a doodlebug has not eaten anant within three time steps at the end of the third time step it will starve und die The dood should be removed from the prid of cells During one turn all the doodle should move before the Be sure to include a default constructor mutators and accessons for all private member variables Class Organism: Create a dass named that enciones basic data common to ants and doodiebus This class should have several virtual functions that are in the derived classes of Ant and Doodlebog vold movel-rules to move the critter void breed) - whether or not to breed int ge Type - return it ant or doodiebog bool starvel determine if the organism staves Be sure to include a default constructor mutators and sccessors for all private member variables **Think about which class should stone the location of the critter. If you want to, you can add a World class wnios con generate a world and determine if there's an Ant or Doodlebut on a sociedare The Maino Write a program to implement this simulasice and draw the world using ASCII characters of "O" for an ant and "x" fora doodle fritislize the world with 5 doodlebags and 100 arts. Be sure to use constants. After each time step, promot the user to press Enter to move to the next time step. Methods void Smolote:OneStep. This is the main routine that simulates one turn in the world. First, a bag for each organism used to indicate it it has moved. This is because weiterate through the grid starting from the top looking for an organism to move onemoves down we don't want to move it when we wach it. First move doodles, then ants and if they are still alive then we breed then void Display - Displays the world in ASCIUses otcrant. X For doodiebus You should see accipere poottom ofredatoes ondore, although randon perturbations may lead to elimination at one or both species Our the program last 15 times Nous ut should be done in the prog Sample output Sample output 0.0.0.0 00.000 ... ooox ..0.0...0.0000 xo00o ao XOO....00 000.0000.0 O OX 0000 0........... 0.0....0. .........000 0.0.0....0.0....0 ..00...00.00 ......00.000.00 0.0000.0 000.0 O.Xoo.... 0.0....0...0.0. 00 O. Pressenter for next step 000 0...0.0...0.X ...0...0.000 00.00.0 X 0.00.00.00 X.o.o. ..000,0.000000 X00 ......0.0...0.0 -0.0 0.000 00.000.00 LOODOOD 0.0.0 00.00.00 0.0000 Xooo 00 DO Presenter for next step " 0.000.000 X...0.0...0.0 ........0..0.0..00 Xoo.00.00 ...00.0.0.0....0. OO OOO ............. 0.0...O ........0.00 ..0.0...0...000... 0.0.0.0.0.0.0 ..0....00.0.00.... ***0000 ***Ooor 0. O....0...0... ..00 "O'00 Pressenter for next step XODO 0000 ooroo 0000 00/000 ..0.0.0.00 0.00.00 X.ooo000.0000.0 O'000000" 000 "000000000 ...X.00.000000.000 0.00 0.000...0000 000000" 00.00 0.0 9.0.0...000.00.0 DOO 00000000 "000000000000 0 000/00000 000000000 0 DO 00000 OOO0000OTO 000 00 OO 00 Pressenter for next step Polymorphism Organism Understand the Application The goal for this programming project is to create a simple 2D predator- prey simulation. In this simulation, the prey are ants and the predators are doodlebugs. These critters live in a 2020 grid of cells. Only one critter may occupy a cell at a time. The grid is endosed, so a critter is not allowed to move off the edges of the world. Time is simulated in steps Each critter performs some action every time step. The Program Spec Class Ants: The ants behave according to the following model Move. For every time step, the ants 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 time steps, at the end of the time step (ie, after moving the ant will breed. This is simulated by creating a new ant in an adjacent fup, down, left, or right) cel that is empty. there is no empty cell available, no breeding occurs. Once an offspring is produced, an ant cannot produce an offspring again until it has survived three more time steps Be sure to include a default constructor mutators, and accessors for all private member variables Class Doodlebugs: The doodlebugs behave according to the following model Move. For every time step, the doodlebug will move to andment cell containing an ant and eat the ant. If there are no ants in admin cells, the doodiebug moves according to the same rules as the ant Note that a doodlebug cannot eat other doodlebugs Breed. If a doodlebug survives for echt time steps, at the end of the time step it will spawn of a new doodlebuis in the same marinera Uvant Starve. If a doodlebug has not eaten anant within three time steps at the end of the third time step it will starve und die The dood should be removed from the prid of cells During one turn all the doodle should move before the Be sure to include a default constructor mutators and accessons for all private member variables Class Organism: Create a dass named that enciones basic data common to ants and doodiebus This class should have several virtual functions that are in the derived classes of Ant and Doodlebog vold movel-rules to move the critter void breed) - whether or not to breed int ge Type - return it ant or doodiebog bool starvel determine if the organism staves Be sure to include a default constructor mutators and sccessors for all private member variables **Think about which class should stone the location of the critter. If you want to, you can add a World class wnios con generate a world and determine if there's an Ant or Doodlebut on a sociedare The Maino Write a program to implement this simulasice and draw the world using ASCII characters of "O" for an ant and "x" fora doodle fritislize the world with 5 doodlebags and 100 arts. Be sure to use constants. After each time step, promot the user to press Enter to move to the next time step. Methods void Smolote:OneStep. This is the main routine that simulates one turn in the world. First, a bag for each organism used to indicate it it has moved. This is because weiterate through the grid starting from the top looking for an organism to move onemoves down we don't want to move it when we wach it. First move doodles, then ants and if they are still alive then we breed then void Display - Displays the world in ASCIUses otcrant. X For doodiebus You should see accipere poottom ofredatoes ondore, although randon perturbations may lead to elimination at one or both species Our the program last 15 times Nous ut should be done in the prog Sample output Sample output 0.0.0.0 00.000 ... ooox ..0.0...0.0000 xo00o ao XOO....00 000.0000.0 O OX 0000 0........... 0.0....0. .........000 0.0.0....0.0....0 ..00...00.00 ......00.000.00 0.0000.0 000.0 O.Xoo.... 0.0....0...0.0. 00 O. Pressenter for next step 000 0...0.0...0.X ...0...0.000 00.00.0 X 0.00.00.00 X.o.o. ..000,0.000000 X00 ......0.0...0.0 -0.0 0.000 00.000.00 LOODOOD 0.0.0 00.00.00 0.0000 Xooo 00 DO Presenter for next step " 0.000.000 X...0.0...0.0 ........0..0.0..00 Xoo.00.00 ...00.0.0.0....0. OO OOO ............. 0.0...O ........0.00 ..0.0...0...000... 0.0.0.0.0.0.0 ..0....00.0.00.... ***0000 ***Ooor 0. O....0...0... ..00 "O'00 Pressenter for next step XODO 0000 ooroo 0000 00/000 ..0.0.0.00 0.00.00 X.ooo000.0000.0 O'000000" 000 "000000000 ...X.00.000000.000 0.00 0.000...0000 000000" 00.00 0.0 9.0.0...000.00.0 DOO 00000000 "000000000000 0 000/00000 000000000 0 DO 00000 OOO0000OTO 000 00 OO 00 Pressenter for next step 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