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
|
#pragma once
#include <string>
class Creature
{
public:
enum BunnyName
{
TOM,
ANTHONY,
JAMES,
LEBRON,
PIKE,
SPOKE,
MAX_NAMES
};
enum BunnyColor
{
BROWN,
BLACK,
GREY,
WHITE,
SPOTTED,
MAX_COLORS
};
protected:
BunnyName m_name;
BunnyColor m_color;
std::string m_sex;
int m_age;
public:
Creature(BunnyName name = MAX_NAMES, BunnyColor color = MAX_COLORS, std::string sex = "M", int age = 0);
~Creature();
friend std::ostream& operator<<(std::ostream &out, Creature &creature);
std::string getName();
std::string getColor();
int getAge() { return m_age; }
};
class BunnyGenerator
{
public:
// Generate a random number between min and max (inclusive)
// Assumes srand() has already been called
static int getRandomNumber(int min, int max)
{
static const double fraction = 1.0 / (static_cast<double>(RAND_MAX) + 1.0);
return static_cast<int>(rand() * fraction * (max - min + 1) + min);
}
static Creature generateBunny()
{
Creature::BunnyColor color = static_cast<Creature::BunnyColor>(getRandomNumber(0, Creature::MAX_COLORS - 1));
Creature::BunnyName name = static_cast<Creature::BunnyName>(getRandomNumber(0, Creature::MAX_NAMES - 1));
int age = m_age;
static std::string s_sex[2] = { "M", "F" };
return Creature(name,color, s_sex[getRandomNumber(0,1)], age);
}
};
|