//----------------------------------------------------------------------------
#include "smartintarrayclass.h"
//----------------------------------------------------------------------------
//----Initialize the array to contain no items
smart_int_array::smart_int_array(void) {

Initialize();
}
//----------------------------------------------------------------------------
//----Empty the array
void smart_int_array::Initialize(void) {

TheNumberOfItems = 0;
}
//----------------------------------------------------------------------------
//----Add another item to the array if there is space
boolean smart_int_array::AddItem(int Item) {

//----Check there is space for another item
if (TheNumberOfItems < MAX_INTEGERS) {
//----Store the item and increase the counter
    TheItems[TheNumberOfItems] = Item;
    TheNumberOfItems++;
    return(TRUE);
    }
//----Otherwise not possible
else return(FALSE);
}
//----------------------------------------------------------------------------
//----Get a specified item if it has been stored
boolean smart_int_array::GetItem(int ItemNumber, int& Item) {

//----Check there are that many items
if (ItemNumber >= 1 && ItemNumber <= TheNumberOfItems) {
    Item = TheItems[ItemNumber - 1];
    return(TRUE);
    }
//----Otherwise not possible
else return(FALSE);
}
//----------------------------------------------------------------------------
//----Get the number of items stored
int smart_int_array::NumberOfItems(void) {

//----Simply return that field
return(TheNumberOfItems);
}
//----------------------------------------------------------------------------
//----Total all the items stored
int smart_int_array::Total(void) {

int ItemNumber,
    Item,
    RunningTotal;

//----Set total to 0 then add all the specified items
RunningTotal = 0;
//----Loop until cannot get another item
ItemNumber = 1;
while (GetItem(ItemNumber,Item)) {
    RunningTotal = RunningTotal + Item;
    ItemNumber++;
    }

//----Return the total
return(RunningTotal);
}
//----------------------------------------------------------------------------
//----Average all the items stored
int smart_int_array::Average(void) {

//----Return the total divided by the number of items
return(Total()/TheNumberOfItems);
}
//----------------------------------------------------------------------------
