Hen - the goToSleep method on the superclass Chicken, but...

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

View Full Document Right Arrow Icon
#include "Hen.h" using namespace std ; Hen::Hen() : Chicken("hen, breed not specified") , numConsecutiveEggs(0), typicalConsecutiveEggs(10) { } Hen::Hen(string b) : Chicken(b), numConsecutiveEggs(0), typicalConsecutiveEggs(10) { } /* Here are the same constructors as above, but without the use of initializer lists. Hen::Hen() { newDay = true ; breedName = "hen, breed not specified" ; numConsecutiveEggs = 0 ; typicalConsecutiveEggs = 10 ; } Hen::Hen(string b) { newDay = true ; breedName = b ; numConsecutiveEggs = 0 ; typicalConsecutiveEggs = 10 ; } */ void Hen::goToSleep() { Chicken::goToSleep() ; checkedForAnEggToday = false ; } /* Here is the same goToSleep method that does not call
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: the goToSleep method on the superclass Chicken, but instead just copied the code from that method into this one. The uncommented version above is the better solution. void Hen::goToSleep() { newDay = true ; checkedForAnEggToday = false ; } */ int Hen::feedConsumed() { return 120 ; // 120 grams, a bit above a 1/4 pound } int Hen::laidAnEgg() { // An industrial chicken is fed protien-rich food to increase // egg production. if (checkedForAnEggToday) return 0 ; else { checkedForAnEggToday = true ; if (numConsecutiveEggs <= typicalConsecutiveEggs) { ++ numConsecutiveEggs ; return 1 ; } else { numConsecutiveEggs = 0 ; return 0 ; } } }...
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

Hen - the goToSleep method on the superclass Chicken, but...

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