Question

In: Computer Science

Create the function named multiplyByAverage used below. The multiplyByAverage function is passed a float array and...

Create the function named multiplyByAverage used below. The multiplyByAverage function is passed a float array and its size and multiplies each element of the passed array by the array's average. in C++.


const size_t SIZE = 4;
float floatArray[SIZE] = { 42.5, 74.2, 12.4, 24.3 };

multiplyByAverage(floatArray, SIZE);

//floatArray is now: { 1629.9, 2845.6, 475.5, 931.9 }

Solutions

Expert Solution

code and output

code for copying

#include <iostream>
#include<iomanip>

using namespace std;
void multiplyByAverage(float f[],int size)

{   
float arr[4];
float sum=0;
float average =0;
for(int i=0;i<4;i++)
{
sum=sum + f[i];
}
average=sum/size;
for(int i=0;i<4;i++)
{
arr[i]=f[i]*average;
cout << fixed<<setprecision(1)<<(arr[i])<<" ";
}
  
}


int main()
{
const size_t SIZE =4;
  
float floatArray[SIZE] = { 42.5, 74.2, 12.4, 24.3 };
multiplyByAverage(floatArray,SIZE);
return 0;
  
}


Related Solutions

write a program in C Write a function that is passed an array of characters containing...
write a program in C Write a function that is passed an array of characters containing letter grades of A, B, C, D, and F, and returns the total number of occurrences of each letter grade. Your function should accept both lower and upper case grades, for example, both 'b' and 'B' should be bucketed into your running total for B grades. Any grade that is invalid should be bucketed as a grade of 'I' for Incomplete. You must use...
JAVASCRIPT Create an array of 5 objects named "movies" Each object in the movies array, should...
JAVASCRIPT Create an array of 5 objects named "movies" Each object in the movies array, should have the following properties: Movie Name Director Name Year Released WasSuccessful (this should be a boolean and at least 2 should be false) Genre Loop through all of the objects in Array If the movie is successful, display all the movie information on the page. These movies were a success: Title: Forrest Gump Year Realeased: 1994 Director: Robert Zemeckis Genre: Comedy
c++ please 1. Write and test the function maximum that is passed an array of n...
c++ please 1. Write and test the function maximum that is passed an array of n pointers to integers and returns the maximum value among the n integers. The function must use the travellingpointer(1stversion) notation to traverse the array. The function has the following prototype. int maximum ( int *p [ ], int n); 2. Implement the function psum( )that is passed an array of n floats and returns a pointer to the sum of such an array. Print the...
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.
An exception with finally block lab. Create a new class named ReadArray Create simple array and...
An exception with finally block lab. Create a new class named ReadArray Create simple array and read an element using a try block Catch any exception Add a finally block and print a message that the operation if complete
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++, using pass by reference
Write a function named findIndex that takes an array of integers, the number of elements in...
Write a function named findIndex that takes an array of integers, the number of elements in the array, and two variables, such that it changes the value of the first to be the index of the smallest element in the array, and changes the value of the second to be the index of the largest element in the array. Please complete this in C++
1. Develop a module named temperatures.py with the following functions. Function toCelsius is passed a Fahrenheit...
1. Develop a module named temperatures.py with the following functions. Function toCelsius is passed a Fahrenheit temperature and returns the Celsius equivalent. 1 degree Fahrenheit = 5/9 * (Fahreheit-32) degrees Celsius. Function toFahrenheit is passed a Celsius temperature and returns the Fahrenheit equivalent. 1 degree Celsius = 1.8*Celsisus + 32 degrees Fahrenheit. Function toKPH is passed a speed in miles per hour and returns the kilometers per hour equivalent. 1 kph = mph * 1.609344 Function toMPH is passed a...
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.
Create a function named ‘dividing’. This function will take one parameter value, which will be an...
Create a function named ‘dividing’. This function will take one parameter value, which will be an integer. For the function you will use ‘Exception Handling’ with the use of the try and except statements to try and return the results of a number divided by the parameter value given to the function. If the parameter passed to the function is the integer value of zero then your function should return ‘You tried to divide by zero!’ through the use of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT