Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In C++ code, answer the following parts. The answers do not need to be in a full

ID: 3916928 • Letter: I

Question

In C++ code, answer the following parts. The answers do not need to be in a full program, rather just answers to fullfill the questions.

Part 1: Write a function double average(int a[ ], int size) which returns the average of all elements in int array a.

Part 2: Write a function double average(vector<int> v) which returns the average of all elements in int vector v.

Part 3: Write a function int max(int arr[ ], int size) which returns the maximum value in int array arr.

Part 4: Write a function int min(vector<int> v) that returns the minimum value in int vector v.

Explanation / Answer

#include <iostream>
#include <vector>
using namespace std;
double average(int a[ ], int size){
int total = 0;
for(int i=0;i<size;i++) {
total+=a[i];
}
return total/(double)size;
}
double average(vector<int> v){
int total = 0;
for(int i=0;i<v.size();i++) {
total+=v[i];
}
return total/(double)v.size();
}
int max(int arr[], int size) {
int max = arr[0];
for(int i=1;i<size;i++) {
if(max < arr[i]) {
max = arr[i];
}
}
return max;   
}
int min(vector<int> v) {
int min= v[0];
for(int i=0;i<v.size();i++) {
if(min > v[i]) {
min = v[i];
}
}
return min;   
}
int main()
{

return 0;
}