Please send questions to
st10@humboldt.edu .
/*
a boa is a class
boa(string color, double length,
string food)
...representing a boa with:
a color that is its primary coloring,
a length in meters,
a preferred food
template for a function with a boa parameter a_boa:
ret_type process_boa(boa a_boa)
{
return ... a_boa.get_color() ...
... a_boa.get_length() ...
... a_boa.get_food() ... ;
}
*/
#include "boa.h"
using namespace std;
// :: is called a scope resolution operator,
// and it lets the C++ compiler know that this is implementing
// a method of the class whose name precedes the ::
// (that is, you put boa:: before each method of boa that you
// are implementing in this class implementation file...)
// constructor
// a constructor method needs to specify values for each of
// the new object's data fields
boa::boa(string a_color, double a_length, string a_food)
{
// = means assignment -- assign, or give, each datafield
// of the class an appropriate initial value
color = a_color;
length = a_length;
food = a_food;
}
boa::boa( )
{
color = "green";
length = 6;
food = "alligators";
}
// selectors
string boa::get_color( ) const
{
return color;
}
double boa::get_length( ) const
{
return length;
}
string boa::get_food( ) const
{
return food;
}
// modifier methods
void boa::set_length(double new_length)
{
length = new_length;
}
void boa::set_color(string new_color)
{
color = new_color;
}
void boa::set_food(string new_food)
{
food = new_food;
}
// other methods
// signature: boa::longer_than: boa -> bool
// purpose: expects another boa, and produces whether the
// calling boa is longer in length than the given
// ther boa
// examples:
// boa george("purple", 75, "dragons");
// boa carol("green", 6, "alligators");
// carol.longer_than(george) == false
// george.longer_than(carol) == true
// george.longer_than(george) == false
bool boa::longer_than(boa another_boa) const
{
return length > another_boa.length;
}
// signature: boa::longer_than: double -> bool
// purpose: expects a length in meters, and produces whether
// the calling boa is longer than this given length
// examples:
// boa carol("green", 6, "alligators");
// carol.longer_than(7) == false
// carol.longer_than(6) == false
// carol.longer_than(5) == true
bool boa::longer_than(double given_length) const
{
return length > given_length;
}