A local government organization has been testing a new biological triggering device. The actual cost has gotten out of hand and they have recruited you to test the new style trigger through ‘simulation’. How does the trigger work?
 The trigger device is a 20 by 20 grid where each square is a sensor. Each square in the grid starts with one flea. (The flea is the biological part) All the fleas jump at the same time and land on a neighboring square or the current square. So some squares now have more than one flea and other squares blank or without a flea. The fleas continue to jump and at some point when 83% of the squares are blank (no fleas) the trigger is fired. If the flea jumps off the 20 x 20 grid, the flea is zapped and will no longer be able to jump.
 Using actual fleas and the termination of the fleas during testing became the big cost over run the government was having to deal with. Zapping electronic fleas is cheaper than real fleas.
 Now to simulate this process, we need to know which way a given flea will jump. A flea will only jump to a neighboring square and never two or more squares over. (These fleas are breed with shorter legs so they can’t jump as far.) Now after much research, it was determine which direction a flea will jump. There are nine places/squares a flea can land, the neighboring square or the square the flea is currently jumping from. A flea will jump in one of the corner squares 5% of the time. Each corner is 5%. The top, bottom, left and the current square the flea will jump in 15% of the time and to the right 20% of the time. 20% direction is the way the dog’s hair grows and the fleas jump with the hair a little more often than in the other directions. A flea is in the middle square and the directions the flea will jump are shown below.
                           5     15   5
                          15   15   20
                          5     15   5
  A simulation consists of setting one flea on each square then letting each flea jump. After each jumps check to see if 83% of the squares are empty. If they are not, then let each flea jump again. You continue letting the fleas jump until 83% of the squares are empty and the simulation stops, ie the bomb is detonated. Now since jumping is random movements, running one simulation will not be enough information needed to accomplish this task. You will need to run the simulation again and again to get an average. You will need to run the simulation 2500 times and then compute the following resulting values.
   Inputs:             None
  Outputs:           1. How many times will the fleas jump before the trigger is fired?
 2. If fleas jumps 4 times every 7 seconds, determine how much time does one      have to clear the area before the trigger is fired?
 3. What is the shortest time and the longest time you computed, given all           simulations, which was needed to clear the area?
              4. How many fleas on the average were lost before the trigger was fired? (This                   is to show the government the cost savings for using simulation rather than
                    using real fleas in a simulation.)
   Restrictions:      Use 2-d arrays(2). Run the simulation 2500 times to generate the results.
   Output:            Format output in a readable style.
   #include 
 #include  #include   using namespace std;  int N = 20;  int checkSquares(int[][20]); void jumpFleas(int[][20], int[][20], int &); void resetGrid(int[][20], int[][20]); void zeroOut(int[][20]); void initialize(int[][20]); void getTotals(int, int, int, int); void getMinMax(int, int, int); void displayInfo(int, int, int, int);  int main() {     int simRun = 0;     int min = 10000, max = 0, jumps = 0, loss = 0, runs = 0;     int TOTALJ = 0, TOTALL = 0;     int grid1[20][20];     int grid2[20][20];     initialize(grid1);     zeroOut(grid2);          while (simRun <= 2000)     {         while (runs != 1)         {             jumpFleas(grid1, grid2, loss);             jumps += 1;             runs = checkSquares(grid2);             resetGrid(grid1, grid2);             zeroOut(grid2);         }         cout << jumps << endl;         cout << loss << endl;         simRun++;     }          getTotals(jumps, loss, TOTALJ, TOTALL);     getMinMax(jumps, min, max);          displayInfo(TOTALJ, TOTALL, min, max);          return 0; }  void jumpFleas(int grid1[][20], int grid2[][20], int &loss) {     int r, c, move;          for (r = 1; r < 20; r++)     {         for (c = 1; c < 20; c++)         {             move = (rand() % 100) + 1;                          if (move > 0 && move < 16)             {                 grid2[r][c] += grid1[r][c];             }             if (move > 15 && move < 31)             {                 grid2[r + 1][c] += grid1[r][c];                 if ((r + 1) == 20)                 {                     loss += 1;                 }             }             if (move > 30 && move < 36)             {                 grid2[r + 1][c + 1] += grid1[r][c];                 if (((r + 1) == 20) || ((c + 1) == 20))                 {                     loss += 1;                 }             }             if (move > 35 && move < 56)             {                 grid2[r][c + 1] += grid1[r][c];                 if ((c + 1) == 20)                 {                     loss += 1;                 }             }             if (move > 55 && move < 61)             {                 grid2[r - 1][c + 1] += grid1[r][c];                 if (((r - 1) == 0) || ((c + 1) == 20))                 {                     loss += 1;                 }             }             if (move > 60 && move < 76)             {                 grid2[r - 1][c] += grid1[r][c];                 if ((r - 1) == 0)                 {                     loss += 1;                 }             }             if (move > 75 && move < 81)             {                 grid2[r - 1][c - 1] += grid1[r][c];                 if (((r - 1) == 0) || ((c - 1) == 0))                 {                     loss += 1;                 }             }             if (move > 80 && move < 96)             {                 grid2[r][c - 1] += grid1[r][c];                 if ((c - 1) == 0)                 {                     loss += 1;                 }             }             if (move > 95 && move < 101)             {                 grid2[r + 1][c - 1] += grid1[r][c];                 if (((r + 1) == N) || ((c - 1) == 0))                 {                     loss += 1;                 }             }             move = 0;         }     } }  int checkSquares(int grid2[][20]) {     int r, c, runs;     int count = 0;          for (r = 0; r < 20; r++)     {         for (c = 0; c < 20; c++)         {             if (grid2[r][c] == 0)             {                 count++;             }         }     }          if (count > 299)     {         runs = 1;     }     else     {         runs = 0;     }          return runs; }  void getTotals(int jumps, int loss, int totalJ, int totalL) {     totalJ += jumps;     totalL += loss; }  void getMinMax(int jumps, int min, int max) {     if (jumps < min)     {         min = jumps;     }     if (jumps > max)     {         max = jumps;     } }  void resetGrid(int grid1[][20], int grid2[][20]) {     int r, c;     for (r = 0; r < N; r++)     {         for (c = 0; c < N; c++)         {             grid1[r][c] = grid2[r][c];         }     } }  void zeroOut(int grid2[][20]) {     int r, c;     for (r = 0; r < N; r++)     {         for (c = 0; c < N; c++)         {             grid2[r][c] = 0;         }     } }  void initialize(int grid1[][20]) {     int r, c;     for (r = 0; r < N; r++)     {         for (c = 0; c < N; c++)         {             grid1[r][c] = 1;         }     } }  void displayInfo(int TOTALJ, int TOTALL, int min, int max) {     int avgJUMP, clearTime, avgLOST, maxTime, minTime;     avgJUMP = TOTALJ / 2000;     clearTime = (TOTALJ * 9) / 5;     maxTime = (max * 9) / 5;     minTime = (min * 9) / 5;     avgLOST = TOTALL / 2000;          cout << \"The average number of jumps before fire: \" << avgJUMP << endl;     cout << \"The amount of time needed to clear the area: \" << clearTime << endl;     cout << \"The shortest time: \" << minTime << endl;     cout << \"The longest time is \" << maxTime << endl;     cout << \"The average number of fleas lost before fire: \" << avgLOST << endl; }