/* For every female aged 2 or older and not radioactive, give birth to a new bunny of the same color and place it at the end of the list */ void BunnyWorld::giveBirth() { Bunny* tracker = m_first->m_next; //find last bunny in list. Bunny* findEnd = tracker; while (findEnd->m_next != nullptr){ findEnd = findEnd->m_next; } //go through whole list while (tracker != nullptr){ if (tracker->getSex() == bny::female && tracker->getAge() >=2 && !tracker->getRadioactive()){ int color = tracker->getColor(); Bunny* newBunny = new Bunny(color); //put new bunny at end of list newBunny->m_next = nullptr; findEnd->m_next = newBunny; findEnd = newBunny; m_population++; if (newBunny->getRadioactive()){ m_radioactivePopulation++; } } tracker = tracker->m_next; } }
//Check to see if there is a Bunny with age >=2 and not radioactive in the population bool BunnyWorld::isEligibleMale() const { Bunny* tracker = m_first->m_next; while(tracker!=nullptr){ if (tracker->getAge() >= 2 && tracker->getSex() == bny::male && !tracker->getRadioactive()){ return true; } tracker = tracker->m_next; } return false; }