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

Write a program that takes an array of 10 integer numbers and calculates the ave

ID: 3917113 • Letter: W

Question

Write a program that takes an array of 10 integer numbers and calculates the average and the sum of the array using two different functions a) (5 pts) Declare and write a function called calcavg. Returns a double, passes the array. Calcavg adds the 10 elements of the array and divides by 10 to return the average Assume there are always 10 elements. Calcavg does not display any result. b) (5 pts) Declare and write a function called calcsum. Returns void. Passes the array and an integer variable by reference. Sums the 10 elements of the array and sets the summation to the variable passed by reference. Calcsum does not display any result. (10 pts). Write a program that has the appropriate headers and variable declarations. program should create an integer array, nums of 10 elements containing the numbers 1,2,3,4,5, 6,7,8,9,10. Please add several comments throughout your program and functions. c) The d) (5 pts). The main program should display the elements of the array using a for loop. The display should look exactly as shown below. Use field width manipulators. e) (5 pts). Call the two functions and display the average and sum of the elements of the array using statements in the main function. The terminal window should look exactly as shown. The elements of nums are: 1 2 3 45 67 8 9 10 The average of nums is 5.50 The sum of nums is 55 Press any key to continue . - .

Explanation / Answer

#include <iostream>

using namespace std;

double calcavg(int arr[]) {
   double total = 0;
   for(int i = 0; i < 10; ++i) {
       total += arr[i];
   }
   return total / 10;
}

void calcsum(int arr[], int &sum) {
   sum = 0;
   for(int i = 0; i < 10; ++i) {
       sum += arr[i];
   }
}

int main() {
   int arr[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
   cout << "The elements of nums are:" << endl;
   for(int i = 0; i < 10; ++i) {
       cout << arr[i] << " ";
   }
   cout << " The average of nums is " << calcavg(arr) << endl;
   int sum;
   calcsum(arr, sum);
   cout << "The sum of nums is " << sum << endl;
   return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote