Please send questions to
st10@humboldt.edu .
/*
a boa is a class
new 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;
}