// ENGR 131, M330 Recitation (Amanda Rohn)
// Homework #9 - List Statistics Class
// Solution

// File: statlist.cpp
// Implementation for class StatList


/*
class StatList
{
public:
	// constructor
	StatList();
	// modification functions
	void addnumber(double num);
	void erase();
	// information functions
	int GetLength();
	double GetSum();
	double GetAvg();
	double GetMin();
	double GetMax();
private:
	// member data
	int length;
	double sum;
	double min;
	double max;
};
*/

#include "statlist.h"
#include <cassert>

StatList::StatList()
{
	length = sum = min = max = 0.0;
}

void StatList::addnumber(double num)
{
	length++;
	sum += num;
	if(length == 1)
	{
		min = max = num;
	}
	else
	{
		if(num > max)
			max = num;
		else if(num < min)
			min = num;
	}
}

void StatList::erase()
{
	length = sum = min = max = 0.0;
}

int StatList::GetLength()
{
	return length;
}

double StatList::GetSum()
{
	return sum;
}

double StatList::GetAvg()
{
	assert(length != 0);
	return sum / length;
}

double StatList::GetMax()
{
	assert(length != 0);
	return max;
}

double StatList::GetMin()
{
	assert(length != 0);
	return min;
}