## balla4eva33

I have this code:

``````void ShapeArr::publishStats()
{
double ap = 0.0;

for (int i=0; i < currCount; i++)
{
Shape *s = arr[i];
ap += s->getAPRatio();
}
cout << "Max APRatio = " << [B]???[/B] << "	Average APRatio = " << ap/currCount << endl;
}``````

What do I need to do to actually calculate the MAX APRatio? "getAPRatio" is being called 3-4 times and returning a single integer each time. Of the 3 or 4 times it's called, I need to somehow compare them and take the biggest one as my max. I think the average is set correctly, but I'm not sure how to separate them and compare them to get the max. Any help??

## Ancient Dragon 5,243

put them in an array then find the max after the loop stops.

## balla4eva33

Then I can't ;get the average though because "ap/currCount" won't work if ap is an array...??

## Salem 5,138

Whenever you have an array, you need to be thinking about using a for loop as well.

## balla4eva33

Ok, I think I got it...:

``````double Max(const double *Numbers, const int Count)
{
double Maximum = Numbers[0];

for(int i = 0; i < Count; i++)
if( Maximum < Numbers[i] )
Maximum = Numbers[i];

return Maximum;
}

void ShapeArr::publishStats()
{
double ap = 0.0;
double tempArr[5];
double x = 0.0;
for (int i=0; i < currCount; i++)
{
Shape *s = arr[i];
ap = s->getAPRatio();
x += s->getAPRatio();
tempArr[i] = ap;
}

double Maximum = Max(tempArr, currCount);
cout << "Max APRatio = " << Maximum << "	";
cout << "	Average APRatio = " << x/currCount << endl;
}``````

Now in my add funcs, I declare new shapes from classes...How do i destruct them/free up the memory of those "new's"??

## Lerner 582

Post deleted, didn't check my internal delay to follow up on posts posted while I was writing mine.

## balla4eva33

Sounds good, but I still need help with how to delete the memory I allocated for all the shapes I called "NEW". I delete "arr" in the shapearr destructor, but how do I properly delete the memory I allocated by the new Rectangle, new Circle, new Triangle, and new RegularPoly in their respective add functions? HELP!?