Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //////////////////////////////////////BUNNY.H/////////////////////////////
- #pragma once
- #define MAX_NAMES 10
- #define MAX_FUR 4
- #include <iostream>
- #include <string>
- class Bunny
- {
- private:
- int age ;
- bool is_male ; // true = male ; false = female
- bool is_mutant ;
- bool procreating ; //meets the requirements for having babies
- bool is_dead ;
- std::string name ;
- std::string fur_color ;
- public:
- Bunny(void) ;
- void Details() ;
- void Progress() ;
- };
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////BUNNY.CPP///////////////////////////////////////////////
- #include "Bunny.h"
- #include <ctime>
- bool Randomize(int percent)
- {
- percent -= 1 ;
- //srand ( time(NULL) ) ; // random giant numbers
- int random = rand() % 100 ; // 0 -99
- if(random >= 0 && random <= percent) // if randm is from 0 to max percent - it hits true
- return true ;
- else
- return false ;
- }
- int Random(int amount)
- {
- //srand( time(NULL) ) ;
- int random = rand() % amount ;
- return random; //max amount of objects
- }
- Bunny::Bunny(void)
- {
- std::string female_name[MAX_NAMES] = {"Martha","Jude","Abigail","Maria","Karina","Nancy","Shaniqua","Francine","Stacey","Hayley"} ;
- std::string male_name[MAX_NAMES] = {"Stan","Vlad","Roger","Turner","Thumper","Darth Vader","Voldemort","Stalin","OJ","Adolf"} ;
- std::string color_of_fur[MAX_FUR] = {"White","Brown","Black","Gray" } ;
- age = 0 ;
- is_male = Randomize(50) ; //Percent Parameter
- if(is_male)
- name = male_name[Random(MAX_NAMES)] ; //max amount of names
- else
- name = female_name[Random(MAX_NAMES)] ;
- fur_color = color_of_fur[Random(MAX_FUR)] ;
- is_mutant = Randomize(2) ;
- std::cout<<"Bunny "<<name<<" was born!"<<std::endl ;
- }
- void Bunny::Details()
- {
- std::cout<<"\nBunnies name is: "<<name<<std::endl ;
- if(is_male)
- std::cout<<name<<" is male"<<std::endl ;
- else
- std::cout<<name<<" is female"<<std::endl ;
- std::cout<<name<<"'s"<<" age is: "<<age<<std::endl ;
- std::cout<<name<<"'s"<<" fur color is: "<<fur_color<<std::endl ;
- if(is_mutant)
- std::cout<<name<<" is a mutant :("<<std::endl ;
- else
- std::cout<<name<<" is healthy :)"<<std::endl ;
- }
- void Bunny::Progress()
- {
- age++ ;
- if(age >= 2)
- procreating= true ;
- if(procreating == true)
- {
- //bunny_list.push_back(Bunny()) ;
- }
- if(age > 10)
- is_dead = true ;
- }
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- ///////////////////////////////////MAIN.CPP////////////////////////////////////////
- #include <list>
- #include <iostream>
- #include "Bunny.h"
- #include <string>
- #include <ctime>
- using namespace std ;
- int main()
- {
- srand ( time(NULL) ) ;
- //typedef list<Bunny> bunny_list ;
- list<Bunny> bunny_list ;
- list<Bunny> dead_bunny_list ;
- list<Bunny>::iterator i ; //= bunny_list.begin();
- //Bunny test ;
- for(int i = 0; i<5; i++)
- {
- bunny_list.push_back(Bunny()) ;
- }
- //i = bunny_list.begin() ;
- //i->Details() ;
- cin.ignore() ;
- return EXIT_SUCCESS ;
- }
Advertisement
Add Comment
Please, Sign In to add comment