title: Map "RABBIT" string to call new "RABBIT"()
body: <p>I have to populate my <code>grid</code> with rabbits, squirrels, wolfs, and cheetahs. I am looking for a mapping of string to type object</p>
  
  <pre><code>populate("CHEETAH", 2);
  populate("WOLF", 3);
  populate("SQUIRREL", 10);
  populate("RABBIT", 10);
  </code></pre>
  
  <p>At the moment, I have this repetitive code that I would like to get rid of.</p>
  
  <pre><code>CELL grid[GRIDHEIGHT][GRIDWIDTH];
  
  void populate()
  {
      int num_rabbits = 0, num_squirrels = 0, num_wolves = 0, num_cheetahs = 0;
      int random, randX, randY;
      srand((int)time(NULL));
  
      while (num_rabbits &lt; 10)
      {
          randX = rand() % GRIDHEIGHT;
          randY = rand() % GRIDWIDTH;
  
          if (!(grid[randX][randY].Has_An_Animal()))
          {
              grid[randX][randY].animal = new RABBIT();
              num_rabbits++;
          }
      }
  
      while (num_squirrels &lt; 10)
      {
          randX = rand() % GRIDHEIGHT;
          randY = rand() % GRIDWIDTH;
  
          if (!(grid[randX][randY].Has_An_Animal()))
          {
              grid[randX][randY].animal = new SQUIRREL();
              num_squirrels++;
          }
      }
  
      while (num_wolves &lt; 3)
      {
          randX = rand() % GRIDHEIGHT;
          randY = rand() % GRIDWIDTH;
  
          if (!(grid[randX][randY].Has_An_Animal()))
          {
              grid[randX][randY].animal = new WOLF();
              num_wolves++;
          }
      }
  
      while (num_cheetahs &lt; 2)
      {
          randX = rand() % GRIDHEIGHT;
          randY = rand() % GRIDWIDTH;
  
          if (!(grid[randX][randY].Has_An_Animal()))
          {
              grid[randX][randY].animal = new CHEETAH();
              num_cheetahs++;
          }
      }
  }//end
  </code></pre>