Write a C++ program in a file titled weighted sum.cpp that prints the weighted average of the elements in an array of integers. Each element is weighted in the sum by its position in the list, so that...

Write a C++ program in a file titled weighted sum.cpp that prints the weighted average of the elements in an array of integers. Each element is weighted in the sum by its position in the list, so that the integer in position i is multiplied by i. The sum is then averaged by the number of elements. Example: Array {1, 2, 8} prints 6 Array {0, 1, 2, 3} prints 3.5 You can assume that the input contains the correct number of elements in the array and that the max length of an array is 100. You may also assume that an array will only contain integers, if non-empty. If the array is empty, it should print the weighted sum as zero.You may only use an array in this assignment, no strings. Assume that the array is read in from a file (or console) that contains the length of the array, followed by the elements in the array. Below is an example of the input and output format. input: 3 1 2 8 output: 6

May 19, 2022
SOLUTION.PDF

Get Answer To This Question

Submit New Assignment

Copy and Paste Your Assignment Here