Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <array>
- #include <algorithm>
- #include <cstdlib>
- #include <ctime>
- #include <cmath>
- class Bunny {
- private:
- bool isMale;
- std::string colour;
- int age;
- std::string name;
- bool isRadioactive;
- bool dead;
- public:
- Bunny(): isMale(0), colour("White"), age(0), name("Place"), isRadioactive(0), dead(0) {}
- void setSex() {
- srand((unsigned)time(NULL));
- isMale = round((double)rand()/(double)RAND_MAX);
- }
- void setColour() {
- srand((unsigned)time(NULL));
- std::array<std::string,4> colours = { "White","Brown","Black", "Spotted" };
- int selector = rand()%3;
- colour = colours[selector];
- }
- void setAge() {
- if(isRadioactive) {
- if(age < 50)
- age++;
- else
- dead = 1;
- }
- else {
- if(age < 10)
- age++;
- else
- dead = 1;
- }
- }
- void setRadioactive() {
- srand((unsigned)time(NULL));
- int chance = (rand()%100)+1;
- if(chance == 2)
- isRadioactive = true;
- }
- void setName() {
- std::vector<std::string> names = {"Thumper","Oreo","Daisy","Bunny",\
- "Bella", "Lily","Charlie","Lola","Molly","Oliver","Jack","Peanut","Coco",\
- "Lucy","Baily","Clover","Smokey","Honey","Fluffy","Ginger","Willow",\
- "Chloe","Bunbun","Gizmo","Snowball"};
- int selection = rand()%names.size();
- name = names[selection];
- }
- bool isDead() {
- return dead;
- }
- friend std::ostream& operator<<(std::ostream& out, Bunny& b);
- };
- std::ostream& operator<<(std::ostream& out, Bunny& b) {
- out << "Name: " << b.name << "\n";
- if(b.isMale)
- out << "Sex: Male\n";
- else
- out << "Sex: Female\n";
- out << "Colour: " << b.colour << "\n";
- out << "Age: " << b.age << " years old\n";
- out << "Radioactive Bunny: " << b.isRadioactive << "\n";
- out << "Is Dead: " << b.dead << "\n";
- return out;
- }
- int main() {
- srand((unsigned)time(NULL));
- std::vector<Bunny> bunnies;
- for(int i = 0; i < 5; i++) {
- bunnies.push_back(Bunny());
- bunnies[i].setSex();
- bunnies[i].setColour();
- bunnies[i].setAge();
- bunnies[i].setRadioactive();
- bunnies[i].setName();
- }
- for(auto i : bunnies)
- std::cout << i << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement