/* Implementation file "IntegerArray.cp" */

/* used in Example answer, Exercise 1, Sheet 6  */

/* Author: Rob Miller and William Knottenbelt
   Program last changed: 30th September 2001 */

#include<iostream>
#include<cmath>
#include"IntegerArray.h"

using namespace std;

/* FUNCTION TO INPUT VALUES FOR THE FIRST number ELEMENTS OF THE ARRAY list  */
void input_array(int list[], int number)
{
	for (int count = 0 ; count < number ; count++)
	{
		cout << "Enter value for element " << count << ": ";
		cin >> list [count];
	}
}
/* END FUNCTION */

/* FUNCTION TO DISPLAY VALUES OF THE FIRST number ELEMENTS OF THE ARRAY list  */
void display_array(int list[], int number)
{
	for (int count = 0 ; count < number ; count++)
	{
		cout.width(5);
		cout << list[count] << " ";
	}
	cout << "\n";
}
/* END FUNCTION */


/* FUNCTION TO COPY THE FIRST number ELEMENTS OF THE ARRAY source_list 
    TO THE FIRST number ELEMENTS OF THE ARRAY target_list*/
void copy_array(int target_list[], int source_list[], int number)
{
	for (int count = 0 ; count < number ; count++)
		target_list[count] = source_list[count];
}
/* END FUNCTION */

/* FUNCTION WHICH RETURNS THE AVERAGE OF THE FIRST 
   number ELEMENTS OF THE FLOAT ARRAY list   */
float average(float list[], int number)
{
	float total = 0;
	for (int count = 0 ; count < number ; count++)
		total += list[count]; 
	return (total / number);
}
/* END FUNCTION */

/* FUNCTION WHICH RETURNS THE AVERAGE OF THE FIRST 
   number ELEMENTS OF THE INTEGER ARRAY list   */
float average(int list[], int number)
{
	float total = 0;
	for (int count = 0 ; count < number ; count++)
		total += float(list[count]); 
	return (total / number);
}
/* END FUNCTION */

/* FUNCTION WHICH RETURNS THE STANDARD DEVIATION OF THE FIRST 
   number ELEMENTS OF THE ARRAY list   */
float standard_deviation(int list[], int number)
{
	float av;
	float element_var[MAXIMUM_SIZE];
	
	av = average(list, number);
	for (int count = 0 ; count < number ; count++)
		element_var[count] = (list[count] - av) * (list[count] - av);
	return sqrt(average(element_var,number)); 
}
/* END FUNCTION */

