Please send questions to
st10@humboldt.edu .
/*-----
Signature: main: void -> int
Purpose: demonstrate a dynamically-allocated array of boas
Examples: when this is run, if the user enters 3 when prompted,
then the following will be printed to the screen:
boa at index 0:
color: green
length: 6
food: alligators
boa at index 1:
color: green
length: 7
food: alligators
boa at index 2:
color: green
length: 8
food: alligators
by: Sharon Tuttle
last modified: 12-3-10
-----*/
#include <iostream>
#include <string>
#include "boa.h"
using namespace std;
int main()
{
boa *my_boas;
int num_boas;
cout << "how many boas do you have? ";
cin >> num_boas;
// create an array of that many boas, using
// the 0-argument constructor
my_boas = new boa[num_boas];
// change the length of each boa to its
// current length plus its array index
for (int i=0; i < num_boas; i++)
{
my_boas[i].set_length( i + my_boas[i].get_length() );
}
// could do other things with the array my_boas
// now, display the boa array contents to the screen
for (int i=0; i < num_boas; i++)
{
cout << "boa at index " << i << ":" << endl;
cout << "color: " << my_boas[i].get_color() << endl;
cout << "length: " << my_boas[i].get_length() << endl;
cout << "food: " << my_boas[i].get_food() << endl;
cout << endl;
}
delete [ ] my_boas;
my_boas = NULL;
return EXIT_SUCCESS;
}