Complete the following program skeleton so it will have a 10-element array of in
ID: 3657989 • Letter: C
Question
Complete the following program skeleton so it will have a 10-element array of int values called fish. When completed, the program should ask how many fish were caught by fishermen 1 through 10, and store this information in the array. Then it should display the following information: (1) Number of fish caught by each fisherman (2) The total number of fish caught by all fishermen (3) The average number of fish caught by the fishermen (4) The highest and lowest number of fish caught by a fisherman (suggest that you also include the # of the fisherman). EXTRA CREDIT (6 points) //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #include using namespace std; int main() { const int NUM_FISHERMEN = 10; //define/declare an array named fish that can hold 10 int values. //You must finish this program so it provides the data as specified above system("PAUSE"); return 0; }Explanation / Answer
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#include <iostream>
using namespace std;
int main()
{
const int NUM_FISHERMEN = 10;
//define/declare an array named fish that can hold 10 int values.
int fish[NUM_FISHERMEN];
// When completed, the program should ask how many fish were caught by fishermen 1 through 10, and store this information in the array.
int i;
for(i = 0; i < NUM_FISHERMEN; i++)
{
cout << "How many fish were caught by fisherman " << i+1 << "? ";
cin >> fish[i];
}
// (1) Number of fish caught by each fisherman
for(i = 0; i < NUM_FISHERMEN; i++)
cout << "Fisherman " << i+1 << " caught " << fish[i] << " fish. ";
// (2) The total number of fish caught by all fishermen
int total = 0;
for(i = 0; i < NUM_FISHERMEN; i++)
total += fish[i];
cout << "Total number of fish caught: " << total << endl;
// (3) The average number of fish caught by the fishermen
double average = (double)total/NUM_FISHERMEN;
cout << "Average number of fish caught: " << average << endl;
// (4) The highest and lowest number of fish caught by a fisherman (suggest that you also include the # of the fisherman).
int min = fish[0];
int min_i = 0;
int max = fish[0];
int max_i = 0;
for(i = 1; i < NUM_FISHERMEN; i++)
{
if(fish[i] > max)
{
max = fish[i];
max_i = i;
}
if(fish[i] < min)
{
min = fish[i];
min_i = i;
}
}
cout << "Highest number of fish caught: " << max << " by fisherman " << max_i+1 << endl;
cout << "Lowest number of fish caught: " << min << " by fisherman " << min_i+1 << endl;
//You must finish this program so it provides the data as specified above
system("PAUSE");
return 0;
}