PLEASE HELP!!!!! C++ Create an array that contains the rainfall amounts for 2016
ID: 3781624 • Letter: P
Question
PLEASE HELP!!!!! C++
Create an array that contains the rainfall amounts for 2016 for Kamloops (make up some data). Write the following functions: getAverage - returns the average rainfall for 2016 getMinimum - returns the smallest rainfall amount for one month for 2016 getMaximum - returns the largest rainfall amount for one month for 2016, AND which month it occurred Write 2 different programs: finds the 3 values described above using a normal for loop, and array subscripts finds the 3 values described above using pointers to work through the array and to return the values (get as much practice as possible using pointers)Explanation / Answer
1) using java as a language.
float getAverage(float [] arr)
{
int l=arr.lenght();
float sum=0;
for(i=0;i<l;i++)
{
sum=sum+arr[i];
}
return sum/l;
}
2)
int month;
float getMinimum(float [] array)
{
int minValue = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] < minValue) {
minValue = array[i];
}
}
return minValue;
}
3)
int month;
public static int getMaxValue(int[] array) {
int maxValue = array[0];
for (int i = 1; i < array.length; i++) {
if (array[i] > maxValue) {
maxValue = array[i];
month=i; // getting the month value
}
}
return maxValue;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.