123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
#include <iostream> using namespace std; int i = 0; int testArray[100] = {0}; bool loopFlag = true; void numbers(int testArray[], int& i) { cin >> testArray[i]; i++; cout << endl; cout << "OK" << endl; return ; } void calcSum(int testArray[]) { int sum = 0; for(int j = 0; j < 100; j++) { sum += testArray[j]; } cout << sum; return; } void findAverage (int testArray[]) { int averageCount = 0; int averageSum = 0; for(int k = 0; k < 100; k++) { if(testArray[k] > 0) { averageCount++; averageSum += testArray[k]; } } cout << static_cast<double>(averageSum) / averageCount; return; } void biggest(int testArray[]) { int largest = 0; for(int i; i < 100; i++) { if(testArray[i] > largest) { largest = testArray[i]; } } cout << endl; cout << largest; return; } void mode(int testArray[]) { } void numCount(int testArray[]) { int howMany = 0; for(int j = 0; j < 100; j++) { if(testArray[j] > 0) { howMany++; } } cout << howMany; } void median(int testArray[]) { int tmp; for (int i = 0; i < 5 -1; i++) { for (int j = i+1; j < 5; j++) { if (testArray[i] > testArray[j]) { tmp = testArray[i]; testArray[i] = testArray[j]; testArray[j] = tmp; } } } int howMany = 0; for(int j = 0; j < 100; j++) { if(testArray[j] > 0) { howMany++; } } int medianNum = (howMany / 2) + 1; int median = testArray[medianNum]; cout << median; } int main() { char command; cout << "Welcome to Stats Array!" << endl; cout << "These are your choices:" << endl; cout << "N - Numbers" << endl; cout << "S - Sum of all" << endl; cout << "A - Average of all" << endl; cout << "B - Biggest of all" << endl; cout << "F - Most Frequent of all" << endl; cout << "H - How many numbers" << endl; cout << "M - Median of all" << endl; cout << "Q - Quit" << endl; do { cin >> command; cout << endl; switch(command) { case 'N': numbers(testArray, i); break; case 'S': calcSum(testArray); break; case 'A': findAverage(testArray); break; case 'B': biggest(testArray); break; case 'F': mode(testArray); break; case 'H': numCount(testArray); break; case'M': median(testArray); break; default: cout << "END"; } }while(loopFlag); return 0; }