Breeds - return 1 else numConsecutiveEggs = 0 return 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 "Speckled Sussex" ; } ; // 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 <= typicalConsecutiveEggs && daysSinceLastBreak < 20) { ++ numConsecutiveEggs ; ++ daysSinceLastBreak ; return 1 ; } else { numConsecutiveEggs = 0 ; if (daysSinceLastBreak >= 20) daysSinceLastBreak = 0 ; return 0 ; } } } string SilverLacedWyandotte::breed() const { return "Silver-laced Wyandotte" ; } ;...
View Full Document

This note was uploaded on 10/28/2010 for the course CSCI 1113 taught by Professor Staff during the Spring '08 term at Minnesota.

Page1 / 2

Breeds - return 1 else numConsecutiveEggs = 0 return 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