Create a simulator of chasing animals. Requirements: Create a function that disp
ID: 3936735 • Letter: C
Question
Create a simulator of chasing animals. Requirements: Create a function that displays a two-dimensional array. The example uses a 35 X 35 array. If the stored value is 0, show "otherwise show the stored number. Use two-dimensional array, nested loops, and if statement. In the main program, set the randomly selected starting locations for each number/animal. The example uses number 1 through number 6. Move each number/animal so that an animal chases the next animal. For example, animal # 1 chases animal # 2, animal # 2 chases animal # 3, and animal # 6 (the last animal) chases animal # l(the first animal). Use modulus division, as well as if statements. You may choose the direction of the movement to either four directions or eight directions. Repeat Number 3 at least 20 times. Show the trace of each animal's numbers. Use a loop. You may use system ("CLS"); to clear the screen, and system("pause"); to pause after each iteration.Explanation / Answer
Please explain Part (2) a bit more so that its clearer to program from there onwards. Before that the code is as follows.
#include <iostream>
//#include<conio>
#include<cstdlib>
using namespace std;
using System;
int animal[35][35],i,j;
void display();
int main()
{
//Array initialization
for(i=0;i<35;i++)
{
for(j=0;j<35;j++)
{
animal[i][j] = rand() % 5;
}
}
display();
system("PAUSE");
return 0;
}
void display()
{
for(i=0;i<35;i++)
{
for(j=0;j<35;j++)
{
(animal[i][j] == 0) ? cout<< "." : cout<<animal[i][j];
cout<<" ";
}
cout<<endl;
}
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.