meissner61

Bunny Sim

Sep 24th, 2011
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.46 KB | None | 0 0
  1. //////////////////////////////////////BUNNY.H/////////////////////////////
  2.  
  3. #pragma once
  4. #define MAX_NAMES 10
  5. #define MAX_FUR 4
  6.  
  7. #include <iostream>
  8. #include <string>
  9.  
  10. class Bunny
  11. {
  12. private:
  13.     int age ;
  14.     bool is_male ;        // true = male ; false = female
  15.     bool is_mutant ;
  16.     bool procreating ;    //meets the requirements for having babies
  17.     bool is_dead ;
  18.     std::string name ;
  19.     std::string fur_color ;
  20.  
  21.  
  22. public:
  23.     Bunny(void) ;
  24.     void Details() ;
  25.     void Progress() ;
  26. };
  27.  
  28.  
  29. ////////////////////////////////////////////////////////////////////////////////////
  30. ////////////////////////////////////////////////////////////////////////////////////
  31. ////////////////////////////////////////////////////////////////////////////////////
  32.  
  33.  
  34. ////////////////////////BUNNY.CPP///////////////////////////////////////////////
  35.  
  36. #include "Bunny.h"
  37. #include <ctime>
  38.  
  39.  
  40.  
  41. bool Randomize(int percent)
  42. {
  43.     percent -= 1 ;
  44.  
  45.     //srand ( time(NULL) ) ; // random giant numbers
  46.  
  47.     int random = rand() % 100 ; // 0 -99
  48.    
  49.  
  50.     if(random >= 0 && random <= percent) // if randm is from 0 to max percent - it hits true
  51.         return true ;
  52.  
  53.     else
  54.         return false ;
  55. }
  56.  
  57. int Random(int amount)
  58. {
  59.     //srand( time(NULL) ) ;
  60.  
  61.     int random = rand() % amount ;
  62.  
  63.     return random;  //max amount of objects
  64. }
  65.  
  66.  Bunny::Bunny(void)
  67. {
  68.     std::string female_name[MAX_NAMES] = {"Martha","Jude","Abigail","Maria","Karina","Nancy","Shaniqua","Francine","Stacey","Hayley"} ;
  69.     std::string male_name[MAX_NAMES] = {"Stan","Vlad","Roger","Turner","Thumper","Darth Vader","Voldemort","Stalin","OJ","Adolf"} ;
  70.  
  71.     std::string color_of_fur[MAX_FUR] = {"White","Brown","Black","Gray" } ;
  72.  
  73.     age = 0 ;
  74.     is_male = Randomize(50) ; //Percent Parameter
  75.  
  76.     if(is_male)
  77.         name = male_name[Random(MAX_NAMES)] ; //max amount of names
  78.     else
  79.         name = female_name[Random(MAX_NAMES)] ;
  80.  
  81.     fur_color = color_of_fur[Random(MAX_FUR)] ;
  82.  
  83.     is_mutant = Randomize(2) ;
  84.  
  85.     std::cout<<"Bunny "<<name<<" was born!"<<std::endl ;
  86. }
  87.  
  88.  void Bunny::Details()
  89.  {
  90.         std::cout<<"\nBunnies name is: "<<name<<std::endl ;
  91.  
  92.         if(is_male)
  93.             std::cout<<name<<" is male"<<std::endl ;
  94.         else
  95.             std::cout<<name<<" is female"<<std::endl ;
  96.  
  97.         std::cout<<name<<"'s"<<" age is: "<<age<<std::endl ;
  98.         std::cout<<name<<"'s"<<" fur color is: "<<fur_color<<std::endl ;
  99.  
  100.         if(is_mutant)
  101.             std::cout<<name<<" is a mutant :("<<std::endl ;
  102.         else
  103.             std::cout<<name<<" is healthy :)"<<std::endl ;
  104.  }
  105.  
  106.  void Bunny::Progress()
  107.  {
  108.      age++ ;
  109.  
  110.      if(age >= 2)
  111.          procreating= true ;
  112.  
  113.      if(procreating == true)
  114.      {
  115.          //bunny_list.push_back(Bunny()) ;
  116.      }
  117.  
  118.  
  119.  
  120.      if(age > 10)
  121.          is_dead = true ;
  122.  }
  123.  
  124. ////////////////////////////////////////////////////////////////////////////////////
  125. ////////////////////////////////////////////////////////////////////////////////////
  126. ////////////////////////////////////////////////////////////////////////////////////
  127.  
  128. ///////////////////////////////////MAIN.CPP////////////////////////////////////////
  129.  
  130. #include <list>
  131. #include <iostream>
  132. #include "Bunny.h"
  133. #include <string>
  134. #include <ctime>
  135.  
  136.  
  137. using namespace std ;
  138.  
  139.  
  140.  
  141. int main()
  142. {
  143.     srand ( time(NULL) ) ;
  144.  
  145.     //typedef list<Bunny> bunny_list ;
  146.  
  147.     list<Bunny> bunny_list ;
  148.     list<Bunny> dead_bunny_list ;
  149.  
  150.     list<Bunny>::iterator i ;  //= bunny_list.begin();
  151.  
  152.     //Bunny test ;
  153.  
  154.     for(int i = 0; i<5; i++)
  155.     {
  156.         bunny_list.push_back(Bunny()) ;
  157.     }
  158.  
  159.  
  160.     //i = bunny_list.begin() ;
  161.  
  162.     //i->Details() ;
  163.  
  164.    
  165.  
  166.  
  167.  
  168.     cin.ignore() ;
  169.     return EXIT_SUCCESS ;
  170. }
Advertisement
Add Comment
Please, Sign In to add comment