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 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
#include<iostream>
using namespace std;
// Prototypes
int getArray(int[]);
int calculateAverage(int[], int);
int variance(int, int, int);
void display(int[], int, int);
int main()
{
int numArray[10]; // user can enter up to 10 numbers
int variance; // adding numbers
int arrayLength;
int total;
int average;
cout << "*~~**~~**~~**~~**~~**~ Simple Statistical Analysis ~**~~**~~**~~**~~*~~**~~*" << endl << endl;
cout << " Max of numbers being entered is 10, -1 will end entering numbers" << endl << endl;
arrayLength = getArray(numArray); // read in array from user
total = calculateAverage(numArray, arrayLength); // get total of numbers
display(numArray, variance, total); // show values and results
system("pause");
return 0;
}
int getArray(int numArray[])
// Purpose: To ask for Numbers
// Parameters: NumArray - up to 10
// Return: N/A
{
int num = 0;
int numofScores = 0;
cout << " Enter Number: ";
cin >> num;
while ((num != -1) && (numofScores < 10))
{
numArray[numofScores] = num;
numofScores++;
if (numofScores < 10)
{
cout << " Enter Number: ";
cin >> num;
}
}
return numofScores;
}
int calculateAverage(int numArray[], int arrayLength)
// Purpose: To calucate the average of numbers given
// Parameters: Average
// Return: Sum of all Numbers
{
int num = 0;
int numofScores = 0;
int array[10];
int average;
int times;
for (numofScores = 0; numofScores < num; ++numofScores)
{
num += array[numofScores];
}
average = num / arrayLength;
cout << " The average is: " << average << endl;
cout << endl;
return num;
}
int variance(int num[], int length, int mean)
// Purpose: To calucate the average of numbers given
// Parameters: Average
// Return: Sum of all Numbers
{
int variance = 0;
variance = ((num[0]-mean)*(num[0]-mean)+(num[1]-mean)*(num[1]-mean)+(num[2]-mean)*(num[2]-mean)+(num[3]-mean)*(num[3]-mean)+
(num[4]-mean)*(num[4]-mean)+(num[5]-mean)*(num[5]-mean)+(num[6]-mean)*(num[6]-mean)+(num[7]-mean)*(num[7]-mean)+(num[8]-mean)*(num[8]-mean)
+(num[9]-mean)*(num[9]-mean)) / 7;
return variance;
}
void display(int numArray[], int average, int variance)
// Purpose: Writes out the items wthin the array and the sum
// Parameters: Accepts an array of integars
// Return: Main
{
int num = 0;
int numofScores = 0;
int arrayLength;
cout << "Variance: " << variance << endl;
cout << "Average: " << average << endl;
cout << "Array: ";
for(numofScores = 0; numofScores < arrayLength; ++numofScores)
{
num = numArray[numofScores];
cout << num << " , ";
}
return;
}
// cout << "Length: " << arrayLength << endl;
|