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 method named minimumValue, which returns the smallest value in an array that is passed...
Write a method named minimumValue, which returns the smallest value in an array that is passed (in) as an argument. The method must use Recursion to find the smallest value. Demonstrate the method in a full program, which does not have to be too long regarding the entire code (i.e. program). Write (paste) the Java code in this word file (.docx) that is provided. (You can use additional pages if needed, and make sure your name is on every page...
Write a method named minimumValue, which returns the smallest value in an array that is passed...
Write a method named minimumValue, which returns the smallest value in an array that is passed (in) as an argument. The method must use Recursion to find the smallest value. Demonstrate the method in a full program, which does not have to be too long regarding the entire code (i.e. program). Write (paste) the Java code in this word file (.docx) that is provided. (You can use additional pages if needed, and make sure your name is on every page...
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...
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...
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
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 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.
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++
Write a function named timesOfLetter that reads an array and returns the number of times of...
Write a function named timesOfLetter that reads an array and returns the number of times of each lowercase letter and each uppercase letter appear in it, using reference parameter. • Write a function named timesOfNumber that reads an array and returns the number of times of each odd number, and each even number appear in it, using reference parameter. • Write a function named isChar() that determines if the input is alphabetic or not during inputting. • Write a function...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT