Question

In: Computer Science

Write a C++ function that receives an integer array along with its specified length. The function...

Write a C++ function that receives an integer array along with its specified length. The function will replace only one of the smallest integers and one of the largest integers by 0. Then the function will return the average for the rest of the values in the array.

Test case array: 3, 8, 2, 6, 5, 3, 4, 7, 8, 2, 10, 7

Function should return: 5.3

Solutions

Expert Solution

SOURCE CODE

#include <iostream>
using namespace std;
int main()
{
int n, i, max=0, min=999999;
float num[100], sum=0.0, average;
cout << "Enter the numbers of data: ";
cin >> n;
for(i = 0; i < n; ++i)
{
cout << i + 1 << ". Enter number: ";
cin >> num[i];
  
if(num[i] > max) max = num[i];
if(num[i] < min) min = num[i];
  
sum += num[i];
}
sum = sum - max - min;
average = sum / (n-2);
cout << "Average = " << average;
return 0;
}

SCREENSHOT

please give a upvote if u feel helpful


Related Solutions

1) Write a function that receives a pointer to an array along with the size of...
1) Write a function that receives a pointer to an array along with the size of the array, it returns the largest number in the array. 2) Write a function that receives a string and returns the length of it.
C++: Write a reverse function that receives a reference to a integer linked list and reverses...
C++: Write a reverse function that receives a reference to a integer linked list and reverses the order of all the elements in it. For example, if the input linked list is 1 -> 4-> 2-> 3-> 6-> 5}, after processing by this function, the linked list should become 5-> 6-> 3-> 2-> 4-> 1. You need to write a main file to insert elements into the linked list and call the reverseLinkedList() function which takes the reference of first...
Write a c program Write a function to swap two elements of an integer array. Call...
Write a c program Write a function to swap two elements of an integer array. Call the function to swap the first element, i[0] with last element i[n], second element i[1] with the last but one element i[n-1] and so on. Should handle arrays with even and odd number of elements. Call the swap function with the following arrays and print results in each case before and after swapping. i. int arr1[] = {0, 1, 2, 3, 30, 20, 10,...
Write a C function to swap the first and last elements of an integer array. Call...
Write a C function to swap the first and last elements of an integer array. Call the function from main() with an int array of size 4. Print the results before and after swap (print all elements of the array in one line). The signature of the arrItemSwap() function is: void arrItemSwap(int *, int, int); /* array ptr, indices i, j to be swapped */ Submit the .c file. No marks will be given if your pgm does not compile...
C++ (cpp) PLEASE Write a complete function (prototype and definition) that takes an integer array and...
C++ (cpp) PLEASE Write a complete function (prototype and definition) that takes an integer array and the array dimensions as an input. The function should then square each value of the array in-place. At the completion of the function return a Boolean which indicates the process has completed.
Create a Java program with a method that searches an integer array for a specified integer...
Create a Java program with a method that searches an integer array for a specified integer value **(see help with starting the method header below). If the array contains the specified integer, the method should return its index in the array. If not, the method should throw an Exception stating "Element not found in array" and end gracefully. Test the method in main with an array that you make and with user input for the "needle". starting header ** public...
In C language: Write a function which can receive a float array, an integer number(number of...
In C language: Write a function which can receive a float array, an integer number(number of elements) as input arguments and print all the elements in the array with 2 decimal precision.
Using C++ Write a template function that accepts an integer parameter and returns its integer square...
Using C++ Write a template function that accepts an integer parameter and returns its integer square root. The function should return -1, if the argument passed is not integer. Demonstrate the function with a suitable driver program .
Write a java script function that accepts integer array as input, and display a new array...
Write a java script function that accepts integer array as input, and display a new array by performing fol lowing modifications, • The values in odd index positions must be incremented by 1 • The values in even index positions must be decremented by 1. • Assume the array index starts from 0. Input 1: arr = [1,2,3,4] Output 1: arr = [0,3,2,5 it done html and javascript and plz do it in simple way
In C language: Write the fnFindMin function which can receive a float array, an integer number(number...
In C language: Write the fnFindMin function which can receive a float array, an integer number(number of elements) as input arguments and finds the minimum value in the array. This function should return the array index (subscript) of the minimum value.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT