This is what I have so far, could someone please let me know if I am doing this right. Also this is what else I have to figure out-
The class should include the following methods:
Sum – I am pretty sure I have this part done right.
CountNmbrsBigger – provide a count of the number of data elements in the array that are larger than a given integer.
Average – provides an average of the data in an array.
High – I am pretty sure I have this part done right.
Low –I am pretty sure I have this part done right.
Find(number) – Returns the first index of the location of the number in the array.
CODE
int main() {
int arrayOfInts1[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
int arrayOfInts2[10];
int arrayOfInts3[] = {1,2,3,4,5,
6,7,8,9,10}; /* an unsized array */
int arrayOfInts4[10];
int i;
arrayOfInts2[0] = 1;
arrayOfInts2[1] = 2;
arrayOfInts2[2] = 3;
arrayOfInts2[3] = 4;
arrayOfInts2[4] = 5;
arrayOfInts2[5] = 6;
arrayOfInts2[6] = 7;
arrayOfInts2[7] = 8;
arrayOfInts2[8] = 9;
arrayOfInts2[9] = 10;
for(i=0; i<10; i++) {
arrayOfInts4[i] = i + 1;
}
return 0;
}
class ArrayClass {
private:
public:
int *theArray;
int theArraySize;
ArrayClass(int [], int);
int sum(void);
int countNmbrsBigger(int);
int average(void);
int high(void);
int low(void);
int find(int);
};
ArrayClass::ArrayClass(int anArray[], int ArraySize){
//constructor
theArray = anArray;
theArraySize = ArraySize;
}
int ArrayClass::sum(void){
//sum of all the data in the array
int sum = 0;
for (int i = 0; i < theArraySize; i++){
sum += theArray[i];
}
return sum;
}
int ArrayClass::high(void){
//find the highest value in the array
int highValue = theArray[0];
for (int i = 0; i > theArraySize; i++){
if (theArray[i] > highValue){
highValue = theArray[i];
}
}
return highValue;
}
int ArrayClass::low(void){
//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;
}