Rapunzel, Can you help again? Please, when I test this I cannot even pause the p
ID: 3626073 • Letter: R
Question
Rapunzel,Can you help again? Please,
when I test this I cannot even pause the program to see where I am at. Thanks for getting me started.
Add the following functions to your program:
Sum – return a sum of all of the data in the array
CountNmbrsBigger – return a count of the number of data elements in the array that are larger than a given integer
Average – returns an average of the data in an array
High – returns the highest value in the array
Low – returns the lowest value in the array
Find(number) – returns the first index of the location of the number in the array
Test your class by creating a main function and an array with 10 numbers, invoking each function and displaying the results to the screen.
#include <iostream>
using namespace std;
int sum(int [], int);
int countNmbrsBigger(int [], int, int);
int average(int [], int);
int high(int [], int);
int low(int [], int);
int find(int [], int, int);
int main (void ){
//test the array class
const int arraySize = 10;
int theArray[arraySize] = {1, 5, 25, 10, 12, 9, 24, 24, 22, 2};
cout << "Sum: " << sum(theArray, arraySize) << endl;
cout << "Count of numbers bigger than 10: " << countNmbrsBigger(theArray, arraySize, 10) << endl;
cout << "Average: " << average(theArray, arraySize) << endl;
cout << "High: " << high(theArray, arraySize) << endl;
cout << "Low: " << low(theArray, arraySize) << endl;
cout << "Find: " << find(theArray, arraySize, 25) << endl;
cout << "Find: " << find(theArray, arraySize, 100) << endl;
}
int sum(int theArray [], int theArraySize){
//returns the sum of the values in theArray
int i,sum=0;
for(i=0;i<theArraySize;i++)
sum+=theArray[i];
return sum;
}
int countNmbrsBigger(int theArray [], int theArraySize, int Number){
//count the value in the array greater than
//the parameter
int i,count=0;
for(i=0;i<theArraySize;i++)
if(theArray[i]>Number)
count++;
return count;
}
int average(int theArray [], int theArraySize){
//average the values in the array
average=sum(theArray,theArraySize)/(double)theArraySize;
return average;
}
int high(int theArray [], int theArraySize){
//find the highest value in the array
}
int low(int theArray [], int theArraySize){
//find the lowest value in the array
int lowValue = theArray[0];
for (int i = 0; i < theArraySize; i++){
if (theArray[i] < lowValue){
lowValue = theArray[i];
}
}
return lowValue;
}
int find(int theArray [], int theArraySize, int theNumber){
//return the subscript of the supplied argument
//return -1 if not found
}