Here is the assignment the teacher gave us:
Cane toads are an invasive species in Australia which are causing environmental havoc. The problem is that cane toads are poisonous and nearly all the Australian predators are susceptible to cane toad poisoning. Wherever the toads have reached they have caused a tremendous loss of native species like snakes which attempt to eat toads which look tasty to a snake. About 90% of the at risk populations are killed.
The goal of this assignment is to use a 2D array to represent a region of the earth which will start with one cell selected at random which will have 1 pair of cane toads. The array can be an array of enums where the enums are defined as NONE, BABIES, or ADULTS. The initial configuration will be all cells of the 2D array having value NONE. Then you would call the random function twice to get random integers. Use a random number mod the number of columns (plus one) to get a random column number and do the same to get a random row number. Set this cell's value to ADULTS. This will represent having at least 1 pair of adults who can propagate to neighboring cells.
Your program should then print the array and use getline to read a line of input. The purpose of the getline call is to allow the user to look at the array. I suggest having 20 rows and 50 columns in the array and using "." to represent NONE, "A" to represent ADULTS and "b" to represent BABIES.
After getting the input line the program should propagate to all cells with a NONE value a BABIES value if there is a neighboring cell with ADULTS. There will be 8 neighbors for all cells in the interior of the array. A significant programming simplification can be made by having the actual array be 2 rows and 2 columns larger - that means using a 22x52 array and then if your process rows 1-20 and columns 1-50 the processed cells will all be interior cells.
After changing some cells to BABIES, the array should be printed. Then you need to call a function to change all the BABIES to ADULTS and use getline again to wait until the user is ready to see the next step.
Your program should exit when all the interior cells (20*50 = 1000) are all ADULTS. At that point Australia will be toast.
At some point in execution it might be possible to view a region like this - or maybe it will look like some other common figure...
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................bbb.............................
.................bbAbb............................
................bbAAAbb...........................
................bAAAAAb...........................
................bbAAAbb...........................
.................bbAbb............................
..................bbb.............................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
..................................................
A skeleton program is available in toads.cpp in the class Moodle source collection.
And here is what I have so far:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
|
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdlib>
using namespace std;
int main()
{
char frogs[22][52];
int row;
int col;
int wide= 20;
int deep =50;
enum type {
NONE = '.',
BABIES = 'b',
ADULTS = 'A'
};
int children=0;
int adult=0;
int x, y = 0;
x = rand() % wide;
y = rand() % deep;
frogs[x][y] = ADULTS;
for(int i=0; i < wide +2; i++){
for(int j=0; j < deep + 2; j++){
frogs[i][j] = NONE;
}
}
for (row = 1; row < deep; row++)
{
for (col = 1; col < wide ; col++)
{
bool foundAdult = false;
for(int i=1; i<deep; i++){
for(int j=1; j<wide; j++){
if(frogs[i][j] == ADULTS)
foundAdult = true;
}
}
if (foundAdult)
{
for(int r=-1;r<=1;r++)
{
for(int c=-1;c<=1;c++)
{
if(frogs[col+c][row+r] == NONE && rand()%10 < 2) // Checks all 9 spaces for
// '.' character. If found
{
frogs[col+c][row+r] = BABIES; // Put a tadpole at that location
children++; // Increase by one
}
}
}
}
}
}
//mature
for(int r=-1;r<=1;r++)
{
for(int c=-1;c<=1;c++)
{
if(frogs[col+c][row+r] == BABIES && rand()%10 < 2) // Checks all 9 spaces for
// 'b' character. If found
{
frogs[col+c][row+r] = ADULTS; // Put adult at that location
adult++; // Increase by one
}
}
}
//print
for(int y=1; y < wide; y++){
for(int x = 1; x < deep; x++){
cout << frogs[y][x];
}
cout << endl;
}
system ("pause");
return 0;
}
|
Honestly, im lost, all it does at this point is print b's. I am really new at programming and I need a push in the right direction or just some help. Thanks in advance.