animal.h
// Programmer: Jennifer Leopold Date: November 7, 2015
// File: animal.h
// Purpose: This file contains the definition of the
// Animal class.
#ifndef ANIMAL_H
#define ANIMAL_H
#include <iostream>
#include <string.h>
#include <cstdlib>
#include "Road.h"
using namespace std;
class Animal
{
private:
static const int MAX_STUPIDITY = 100; // Limits on
static const int MIN_STUPIDITY = 0; // m_stupidity
int m_weight; // weight in kg
string m_species; // e.g., "deer", "possum"
int m_width; // # sectors of road that
// animal occupies
int m_stupidity; // % (0..100) that determines
// whether animal runs onto
// road
public:
// Default constructor for Animal
// Preconditions: None
// Postconditions: m_weight set to 10, m_width set to 2,
// m_species set to "possum", and m_stupidity set to 98
Animal() : m_weight(10), m_species("possum"), m_width(2),
m_stupidity(98) { }
// Parameterized constructor for Animal
// Preconditions: 0 < width < Road::MAX_WIDTH, weight > 0,
// 0 <= stupidity <= 100
// Postconditions: m_weight set to weight, m_width set
// to width, m_species set to species, and m_stupidity
// set to stupidity
Animal(const int weight, const string species,
const int width, const int stupidity) :
m_species(species)
{
setWeight(weight);
setStupidity(stupidity);
setWidth(width);
}
// Accessor for m_width
// Preconditions: None
// Postconditions: Value of m_width is returned
int getWidth() const { return(m_width); }
// Accessor for m_weight
// Preconditions: None
// Postconditions: Value of m_weight is returned
int getWeight() const { return(m_weight); }
// Determine whether this animal chooses to run.
// Preconditions: MIN_STUPIDITY <= stupidity <=
// MAX_STUPIDITY
// Postconditions: Returns true if m_stupidity >=
// stupidity; otherwise, return false
bool chooseToRun(const int stupidity) const
{ return(m_stupidity >= stupidity); }
// Overloaded operator for <<
// Preconditions: None
// Postconditions: State of Animal will be output to outs,
// thereby modifying ostream outs
friend ostream& operator <<(ostream& outs, const Animal& a);
private:
// Mutator for m_stupidity
// Preconditions: 0 <= stupidity <= 100
// Postconditions: m_stupidity set to stupidity, not
// to exceed boundary conditions
void setStupidity(const int stupidity);
// Mutator for m_weight
// Preconditions: weight > 0
// Postconditions: m_weight set to weight (minimum 1)
void setWeight(const int weight);
// Mutator for m_width
// Preconditions: 0 < width < Road::MAX_WIDTH
// Postconditions: m_weight set to weight (minimum 1)
void setWidth(const int width);
};
#endif