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 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
|
/*
Program Assignment: Program 6
Program Description: Read data from file, calculate average, maximum value,
minimum value, standard deviation, and display
quartile summary.
*/
//Pre-processing Details
#include <iostream>
#include <iomanip>
#include <fstream>
#include <cmath>
using namespace std;
//Function Prototypes - take a good look at how these are defined
void readData(double[], int &);
double calcAvg(double[], int);
void calcMaxMin(double[], int, int &, int &);
double calcStdDev(double[], int, double);
void outputQuarSum(double[], int, int &, int &, int &, int &);
int main()
{
//Declare Variables
double numbers[500], avgNum = 0.0, stdDev = 0.0;
int arraySize = 0, maxIndex = 0, minIndex = 0;
int q1count = 0, q2count = 0, q3count = 0, q4count = 0;
int maxNum = 0, minNum = 0;
//Get data from file
readData(numbers, arraySize);
//Lets see if we have some data...
for (int i = 0; i < arraySize; i++)
cout << numbers[i] << ' ';
//Use calcAvg() to assign average number
double calcAvg(sales);
//Use calcMaxMin() to get index for maximum/minimum number
calcMaxMin()
//Get standard deviation from data using calcStdDev()
data = calcStdDev();
//Sort data into quartile summary using outputQuarSum()
outputQuarSum(maximum, minimum)
//Output Final Summary
cout << " SUMMARY " << endl;
cout << "----------------------------------------" << endl;
cout << right << fixed << showpoint << setprecision(1);
cout << setw(20) << "Data Elements:" << setw(10) << arraySize << endl;
cout << setw(20) << "Mean:" << setw(10) << avgNum << endl;
cout << setw(20) << "Maximum:" << setw(10) << maxNum << endl;
cout << setw(20) << "Minimum:" << setw(10) << minNum << endl;
cout << setw(20) << "Standard Deviation:" << setw(10) << stdDev << endl;
cout << setw(20) << "Quartile 1 Scores:" << setw(10) << q1count << endl;
cout << setw(20) << "Quartile 2 Scores:" << setw(10) << q2count << endl;
cout << setw(20) << "Quartile 3 Scores:" << setw(10) << q3count << endl;
cout << setw(20) << "Quartile 4 Scores:" << setw(10) << q4count << endl;
cout << "----------------------------------------" << endl;
cout << "END OF JOB TERMINATION" << endl << endl;
return 0;
}
//ReadData() Function Definition: This function will read data from a file
// and store it in an array.
void readData(double numbers[], int &elemNums)
{
//Declare Variables
int count = 0;
ifstream inputFile;
//Open File
inputFile.open("array_pgmdata.txt");
//Read Data from File
while (inputFile >> numbers[count])
count++;
//Assign the number of elements to elemNums
elemNums = count;
//Close File
inputFile.close();
}
//calcAvg() Function Definition: This funtion will calculate the average of all numbers
// in an array.
double calcAvg(double numbers[], int elemNums)
{
//Declare Variables
int array , numbers;
//Sum numbers[]...use a loop
for (array = 0; array < (size -1); array++)
//Return the average of all the numbers of the array
}
//calcMaxMin() Function Definition: This function will determine the index for the maximum
// and minimum number of an array.
void calcMaxMin(double numbers[], int elemNums, int &maxIndex, int &minIndex)
{
//Declare Variables
int maxIndex, minIndex;
double maxValue, minValue;
//Calculate Maximum Value...find highest number...need a loop
for (int start = 0; start , (size - 1); start++)
{
maxIndex = start;
maxValue = scores[start];
for (int index = start + 1; ndex < size; index++)
{
if (scores[index] > maxValue)
{
maxValue = scores[index];
MaxIndex = index;
}
}
swap(scores[maxIndex], scores[start]);
}
//Calculate Minimum Value...find lowest number...need a loop
for (int start = 0; start , (size - 1); start++)
{
minIndex = start;
minValue = scores[start];
for (int index = start + 1; index < size; index++)
{
if (scores[index] > minValue)
{
minValue = scores[index];
MinIndex = index;
}
}
swap(scores[minIndex], scores[start]);
}
}
//calcStdDev() Function Definition: This function will calculate standard deviation
// from the calculated data.
double calcStdDev(double numbers[], int elemNums, double avgNum)
{
//Declare Variables
//Calculate Standard Deviation..implement std dev pseudocode in assignement...use a loop.
for i=0 to arraySize-1
sum = sum + (arrayVal[i] - avg)^2
standDev = sqrt((1.0/arraySize)*sum)
}
//Finish calculating standard deviation and return value
}
//outputQuarSum() Function Definition: This function will display the number of
// scores in each quartile.
void outputQuarSum(double numbers[], int elemNums, int &q1count, int &q2count, int &q3count, int &q4count)
{
//Declare local variables..
int number;
double scores1, scores2, scores3, scores4;
//Assign each score to the proper quartile...use a loop with if-else if structure
for (int index = 0; index < eleNums; index++)
{
scores1 = q1count
scores2 = q2count
scores3 = q3count
scores4 = q4count
}
cout << "quartile1" << q1count << endl;
cout << "quartile2" << q2count << endl;
cout << "quartile3" << q3count << endl;
cout << "quartile4" << q4count << endl;
}
|