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 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
|
#include <iostream>
#include <vector>
#include <cstdlib>
#include <time.h>
#include <string>
//#include "bunny.h"
using std::string;
using std::vector;
using std::cin;
using std::cout;
using std::endl;
class Bunny
{
int id;
string name;
string sex;
string color;
int age;
bool radioactive_mutant_vampire_bunny;
public:
Bunny(int aId, string aName, std::string aSex,string aColor, bool rmvb = false) {
id = aId;
name = aName;
sex = aSex;
color = aColor;
age = 0;
radioactive_mutant_vampire_bunny = rmvb;
}
~Bunny() { cout << name << " had died.\n"; }
int getId() { return id; }
string getName() {return name;}
string getSex() {return sex;}
int getAge() {return age;}
string getColor() {return color;}
bool isMutant() {return radioactive_mutant_vampire_bunny;}
void updateAge() {
if (age > 10) {
age++;
}
}
};
vector<string> maleBunnyNames = { "Jelly Bean", "Snowball", "Peanut",
"Snoop", "Thumper", "Oliver", "Comet", "Stuart", "Midnight", "Billy",
"Caramel", "Freddie", "Pepper", "Riley", "Hopper",
"Pancake", "Spooky", "Chip", "Dusty", "Jesse" };
vector <string> femaleBunnyNames = { "Willow",
"Peaches", "Sprinkles",
"Sunny", "Bon Bon",
"Maggie",
"Snowy", "Lilly", "Flower", "Sugar",
"Angel", "Sweet Pea",
"Snowflake", "Licorice", "Luna",
"Daisy", "Nala", "Gertie", "Milly", "Cookie" };
vector<string> bunnyColors = { "white", "brown", "black", "spotted" };
vector<Bunny> bunnyList;
// Program Start
int main() {
srand (time(NULL)); // Initializes random time
for (int i = 0; i < 5; i++) { // Creates first 5 bunnies
int bunnyId = i;
int sexNum = rand() % 2 + 1; // Random sex number
int mutantPercent = 2; // mutant chance percent
int mutantRoll = rand() % 100 + 1; // random roll for mutant
bool isMutant = false;
std::string randomName;
std::string randomColor = bunnyColors[rand() % 4];
std::string sex;
if (sexNum == 1) { // sets male if 1 & sets name
sex = "male";
randomName = maleBunnyNames[rand() % 20];
}
else { // else sets female & sets name
sex = "female";
randomName = femaleBunnyNames[rand() % 20];
}
if (mutantRoll <= mutantPercent) { // Checks if roll is equal or below percentage
isMutant = true;
}
Bunny bun(bunnyId, randomName, sex, randomColor, isMutant); // Creates instance of bunny
bunnyList.push_back(bun); // Adds bunny to vector
}
for (int i = 0; i < bunnyList.size(); i++) { // For Test purposes only
cout << bunnyList[i].getId() << ", ";
cout << bunnyList[i].getName() << ", ";
cout << bunnyList[i].getSex() << ", ";
cout << bunnyList[i].getAge() << ", ";
cout << bunnyList[i].getColor() << ", ";
cout << bunnyList[i].isMutant() << ", ";
cout << '\n';
}
int temp1 = 0;
do {
for (int i = 0; i < bunnyList.size(); i++) {
bunnyList[i].updateAge();
cout << bunnyList[i].getName() << " is " << bunnyList[i].getAge() << '\n';
}
cout << '\n' << bunnyList.size() << '\n';
temp1++;
} while (temp1 < 20);
int temp;
cin >> temp;
return 0;
}
|