Using a One dimensional array

This is my assignment. It is due at 11:59PM so I could use help fast. I have a lot of other classes so I don't have much time and I'm trying to get points to pass this class.


The standard deviation of a list of numbers is measure of how much the numbers deviate from the average. If the standard deviation is small, the numbers are clustered close to the average. If the standard deviation is large, the numbers are scattered far from the average. The sample standard deviation S, for a list of N numbers x is defined as follows:

S= √((∑_(i=0)^N▒(x_i-x ̅ )^2 )/(N-1))

where x ̅ is the average of the N numbers x1, x2, …. Define a function that takes a partially filled array of numbers as its arguments and returns the standard deviation of the numbers in the partially filled array. Since a partially filled array requires two arguments, the function will actually have two formal parameters: an array parameter and a formal parameter of type int that gives the number of array positions used. Embed your function in a suitable test program.

The numbers in the array will be of type double. The do-while loop inside main() reads in numbers and put them into the array. This do-while loop should continue to read in numbers until either: the user types a negative number, or 100 numbers (hint: MAXSIZE) have been read. Write the condition for the do-while where specified.

Then write a function that will accept an array and print out the contents of the array. This function should accept an array and the number of elements that are to be printed. Before writing the code for this function, write the comments.

Then write another function that will accept an array and calculate the standard deviation of the elements of the array. This function should accept an array and the number of elements that are to be printed. Before writing the code for this function, write the comments. This function will also call the average function, which is provided for you.

I will put my code in the next post. I'm not sure if I'm supposed to change the function or variable identifiers. I'm just going to leave them since I have little time. I don't have much time so it's a little hard to think very clearly right now so my code might not be that great.
Last edited on
Here is what I have so far:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include <iostream>
using namespace std;
void PrintArray(const double [], int);
double stdDev(double [], int);
double average(double [], int);

const int MAXSIZE = 100;

int main()
{
	double array1[100];
	int i = 0;
	double somenumber;

	do
	{
		cout << "Please enter a number to enter into the array or a negative number to stop."<<endl;
		cin >> somenumber;
		if (somenumber >= 0)
		{
			array1[i] = somenumber;
			i++;
		}
	} while (somenumber > 0 || somenumber < MAXSIZE);

	cout << "There were " << i << " numbers entered into the array." << endl;

	PrintArray (a1[i], size);
	stdDev (s[], size);


	return 0;
}


//This function prints to the screen the values contained in the array.  The memory space of the 
//indentifer is passed along.  
void PrintArray(const double a1[i], int size)
{
	count << "The contents of the array are: " << a1[] << endl; 

}

//This function calculates and returns the standard deviation of the array.  The memory location of the 
//array is passed to it.
double stdDev(double s[], int size)
{
	double temp(0);
	temp = ((pow(average(s[], size)),2))/ size-1)
	return (temp);
}


// This function computes the average of the elements of the array
// Input (Arguments): the array itself and the array capacity (portion of array used)
// Output: the average, as a double
double average(double s[], int size)
{
	double sum = 0;

	for(int i = 0; i < size; i++) {
		sum += s[i];
	}
	
	return sum / size;
}



Last edited on
Topic archived. No new replies allowed.