#include <iostream>
#include <time.h>
using namespace std;

class SimpleStats
{
private :
	int count, i;
	float average,sum,stdDev, variance, deviation, value[20];
public :
	void initialise (void);
	void generate (void);
	void calcSum (void);
	void calcAverage(void);
	void calcStdDev (void);
	void display (void);
	SimpleStats(void);
	~SimpleStats(void);
};

void SimpleStats :: initialise (void)
{
	average = 0;	// these 3 lines initialise the variables 
	count = 0;	// used to calculate the sum and average
	sum = 0;
	variance = 0;
	deviation = 0;
	for (i = 0; i < 20; i++) // this loop places -1 in every
	{
			value[i] = -1;	     // element of the array
	}
}

void SimpleStats :: generate (void)
{
	
	srand ((unsigned) time(NULL));

		do	// this loop generates a list of values 		
		{	
			value[count] = rand()%100;
			if (value[count] != 0) count++;//this line keeps count of how many numbers have been entered
		}
		while ((count < 20) && (value[count] != 0)); 
}

void SimpleStats :: calcSum (void)
{
	for (i=0; i <count; i++)// this loop displays the numbers generated
	{
			sum = sum + value[i]; // this line sums the values entered
	}
}

void SimpleStats :: calcAverage (void)
{
	average = sum/count;	// this line calculates the average of the numbers entered
}

void SimpleStats :: display (void)
{
	cout << "\nthe following " << count << " numbers were generated \n";
	for (i=0; i <count; i++)// this loop displays the numbers generated
	{
		cout << "\nvalue [" << i+1 << "] = " << value[i];
	}
	cout << "\n\nThe sum of these numbers is " << sum;
	cout << "\nThe average of these numbers is " << average;
	cout << "\nThe standard deviation of these numbers is " << stdDev << endl;
}

void SimpleStats :: calcStdDev (void)
{
	for (i=0; i <count; i++)// this loop displays the numbers generated
	{
			deviation = deviation + (value[i] - average)*(value[i] - average);
	}
	variance = deviation / count;
	stdDev = sqrt(variance);
}

SimpleStats :: SimpleStats (void)
{
	
}

SimpleStats :: ~SimpleStats (void)
{
}

void main (void)
{
	char again;
	SimpleStats mySimpleStats;

	cout << "This program will calculate the sum and average of a list of numbers \n";
	cout << "the maximum number of values that can be generated is 20 \n";
	cout << "the list will end if a value of zero is generated \n";
	
	do	
	{
		mySimpleStats.initialise();
		mySimpleStats.generate();
		mySimpleStats.calcSum();
		mySimpleStats.calcAverage();
		mySimpleStats.calcStdDev();
		mySimpleStats.display();

		cout << "\nDo you want to generate another list of numbers ? ";
		cin >> again;
	}
	while ((again == 'y') || (again == 'Y'));	// this line checks to see if the user wants another go
	cout << "\n\n	End of program	\n\n";
}
