//----------------------------------------------------------------------------
#include "smartintarraylib.h"
//----------------------------------------------------------------------------
void Initialize(smart_integer_array& AnArray) {

AnArray.NumberOfItems = 0;
}
//----------------------------------------------------------------------------
boolean AddItem(smart_integer_array& AnArray, int Item) {

//----Check there is space for another item
if (AnArray.NumberOfItems < MAX_INTEGERS) {
//----Store the item and increase the counter
    AnArray.Items[AnArray.NumberOfItems] = Item;
    AnArray.NumberOfItems++;
    return(TRUE);
    }
//----Otherwise not possible
else return(FALSE);
}
//----------------------------------------------------------------------------
boolean GetItem(smart_integer_array AnArray, int ItemNumber, int& Item) {

//----Check there are that many items
if (ItemNumber <= NumberOfItems(AnArray)) {
    Item = AnArray.Items[ItemNumber - 1];
    return(TRUE);
    }
//----Otherwise not possible
else return(FALSE);
}
//----------------------------------------------------------------------------
int NumberOfItems(smart_integer_array AnArray) {

//----Simply return that field
return(AnArray.NumberOfItems);
}
//----------------------------------------------------------------------------
int Total(smart_integer_array AnArray) {

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(AnArray,ItemNumber,Item)) {
    RunningTotal = RunningTotal + Item;
    ItemNumber++;
    }

//----Return the total
return(RunningTotal);
}
//----------------------------------------------------------------------------
int Average(smart_integer_array AnArray) {

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