Write a function named stats, that takes an array and the number of elements in the array as arguments. It must compute and print the minimum value in the array, maximum value in the array and the average value of all the values inside the array.
// do comment if any problem arises
//code
#include <iostream>
#include <iomanip>
using namespace std;
void stats(double array[], int n)
{
// declare required variables
double min = array[0];
double max = array[0];
double sum = 0;
// loop through array
for (int i = 0; i < n; i++)
{
// if current element is minimum than min
if (min > array[i])
min = array[i];
// if current element is maximum than max
if (max < array[i])
max = array[i];
// compute sum
sum += array[i];
}
cout << "Minimum element: " << fixed << setprecision(2) << min << endl;
cout << "Maximum element: " << fixed << setprecision(2) << max << endl;
// compute average and print it using sum
double average = sum / n;
cout << "Average: " << fixed << setprecision(2) << average << endl;
}
int main()
{
// array for testing
double array[] = {3.3, 6, 23, 90.2, 45};
stats(array, 5);
}
Output:
Write a function named stats, that takes an array and the number of elements in the...
Write a function template named summarray, with two parameters: and array called are and an int holding the number of elements in arr. The function should return the sum of the elements in arr. this template must work for double or int arrays. Show a sample function call to the template function you wrote. What would you have to do to use the templates sumArray function with an array of objects of a custom class?
1. Write a function named findTarget that takes three parameters: numbers, an array of integers - size, an integer representing the size of array target, a number The function returns true if the target is inside array and false otherwise 2. Write a function minValue that takes two parameters: myArray, an array of doubles size, an integer representing the size of array The function returns the smallest value in the array 3. Write a function fillAndFind that takes two parameters:...
Write a function named insertBeforeKey that takes the parameters as follows list as an char array, capacity for the capacity of the array, numItems has the number of items in the array, key is an element of the array before which newVal is to inserted. Assume key is always present in the array. and newVal has the new value to be inserted into the array. If the array is at capacity then the function should return -1, otherwise return 0...
Write a function named findTarget that takes three parameters: - numbers, an array of integers - size, an integer representing the size of array - target, a number The function returns true if the target is inside array and false otherwise
In c++ 1. Write a function named findTarget that takes three parameters - numbers: an array of integers size: an integer representing the size of array target: a number The function returns true if the target is inside the array and false otherwise 2. Write a function min Valve that takes two parameters: myArray an array of doubles - size: an integer representing the size of array The function returns the smallest value in the array 3 Wrile a funcion...
Write a function named "eliminate_duplicates" that takes an array of integers in random order and eliminates all the duplicate integer integers in the array. The function should take two arguments: (1) an array of integers; (2) an integer that tells the number of cells in the array. The function should return the number of distinct integers in the array.
a) Declare and instantiate an array named scores of twenty-five elements of type int. (b)Write a statement that declares an array namedstreetAddress that contains exactly eighty elements of typechar. 2. In a single statement: declare, create and initialize an arraynamed a of ten elements of type int with the values of the elements (starting with the first) set to 10, 20,..., 100 respectively. 3. Declare an array reference variable, week, and initialize it to an array containing the strings "mon",...
3. Write Java methods to accomplish each of the following Write a method named simpleAry which accepts and return nothing. It creates an array that can hold ten integers. Fill up each slot of the array with the number 113. Then, display the contents of the array on the screen. You must use a loop to put the values in the array and also to display them. Write a method named sury which accepts an array of type double with...
Must be C++ 11 Write a function named insertinArray that takes the following parameters: list: an integer array index: index at which to insert the new item numitems: number of items currently in the array arrayCapacity: capacity of the array newVal: value to insert into the array If the array is at capacity then the function should return-1. Otherwise, insert newVal at index and return O for success int insertInArray(int listl 1, int index, int numItems, int arrayCapacity, int newVal)...
(C++) Write a function, insertAt, that takes four parameters: an array of integers, the number of elements in the array, an integer (say, insertItem), and an integer (say, index). The function should insert insertItem in the array provided at the position specified by index. If index is out of range, output the following: Position of the item to be inserted is out of range or if the index is negative: Position of the item to be inserted must be nonnegative...