Breeds - return 1 ; } else { numConsecutiveEggs = 0 ;...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
#include "Breeds.h" #include <cstdlib> #include <ctime> using namespace std ; // RhodeIslandRed RhodeIslandRed::RhodeIslandRed() : Hen() { typicalConsecutiveEggs = 14 ; } string RhodeIslandRed::breed() const { return "Rhode Island Red" ; } ; // BarredPlymouthRock BarredPlymouthRock::BarredPlymouthRock() : Hen() { typicalConsecutiveEggs = 4 ; } string BarredPlymouthRock::breed() const { return "Barred Plymouth Rock" ; } ; // SpeckledSussex SpeckledSussex::SpeckledSussex() : Hen() { typicalConsecutiveEggs = 3 ; srand(time(NULL)); // random number seed } int SpeckledSussex::laidAnEgg() { // Speckled Sussex is a more random egg layer. if (checkedForAnEggToday) return 0 ; else { checkedForAnEggToday = true ; double randomChance = static_cast< double >( rand() )/RAND_MAX ; randomChance > 0.25) { ++ numConsecutiveEggs ;
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: return 1 ; } else { numConsecutiveEggs = 0 ; return 0 ; } } } string SpeckledSussex::breed() const { return &quot;Speckled Sussex&quot; ; } ; // SilverLacedWyandotte SilverLacedWyandotte::SilverLacedWyandotte() : Hen() { typicalConsecutiveEggs = 4 ; daysSinceLastBreak = 20 ; } int SilverLacedWyandotte::laidAnEgg() { // A Silver-laced Wyandotte takes a few days off once in a while. if (checkedForAnEggToday) return 0 ; else { checkedForAnEggToday = true ; if (numConsecutiveEggs &lt;= typicalConsecutiveEggs &amp;&amp; daysSinceLastBreak &lt; 20) { ++ numConsecutiveEggs ; ++ daysSinceLastBreak ; return 1 ; } else { numConsecutiveEggs = 0 ; if (daysSinceLastBreak &gt;= 20) daysSinceLastBreak = 0 ; return 0 ; } } } string SilverLacedWyandotte::breed() const { return &quot;Silver-laced Wyandotte&quot; ; } ;...
View Full Document

Page1 / 2

Breeds - return 1 ; } else { numConsecutiveEggs = 0 ;...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online