Question: Complete the C++ code with these 3 addons //////////////////////////////////////////////////////////////////////////////////////////////// Source code provided below //////////////////////////////////////////////////////////////////////////////////////////////// #include #include #include #include #define LOWER_BOUND 0.0 #define UPPER_BOUND 150.0 #define

Complete the C++ code with these 3 addons

////////////////////////////////////////////////////////////////////////////////////////////////

Source code provided below

////////////////////////////////////////////////////////////////////////////////////////////////

#include #include #include #include

#define LOWER_BOUND 0.0 #define UPPER_BOUND 150.0 #define MIN_VALUE 30 #define MAX_VALUE 100 #define VALS_PER_LINE 8

using namespace std;

double randDouble() { double d = LOWER_BOUND + ( rand() / (RAND_MAX / (UPPER_BOUND - LOWER_BOUND)));

return d; } int buildArray(double arr[]) { int n = MIN_VALUE + rand() % (MAX_VALUE - MIN_VALUE + 1); for(int i = 0; i

}

void printArray( double array[], int numberOfValues, string title ) { cout

for(int i = 0; i

void sortArray( double array[], int numberOfValues, char sortType ) { int Idx; int n =numberOfValues;

if(sortType=='A'||sortType=='a') { for(int i = 0; i

if(array[j] 0; i--) { Idx = 0; // initialize to subscript of first element for (int j=1; j

int main() { double arr1[MAX_VALUE]; double arr2[MAX_VALUE]; int n1, n2;

srand(0); //srand(time(0));//this also can be used instead of previous line cout

n1 = buildArray(arr1);

printArray(arr1, n1, "First Array -- Unsorted Random Numbers -- " ); sortArray(arr1, n1, 'a'); printArray(arr1, n1,"First Array -- Sorted Random Numbers -- " );

n2 = buildArray(arr2);

printArray(arr2, n2, "Second Array -- Unsorted Random Numbers -- " ); sortArray(arr2, n2,'d'); printArray(arr2, n2, "Second Array -- Sorted Random Numbers -- " );

return 0; }

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Please add the following to the program

1. Display the smallest and largest values in each of the arrays. This should be displayed AFTER displaying the sorted numbers in the array.

2. Write and use a function that will calculate the average of the numbers in an array of doubles. This function should be called for each of the arrays of doubles and the return value should be displayed in main() AFTER displaying the sorted numbers in the array.

double average( double array[], int numberOfValues )

This function will calculate the average of the values in an array of doubles.

This function takes two arguments: the first argument is an array of doubles that holds the numbers to be used in the calculation, and the second argument is an integer that holds the number of values to use in the calculation. The function returns a double: the average of the values in the array of doubles.

3. Write and use a function that will calculate the standard deviation of the numbers in an array of doubles. This function should be called for each of the arrays of doubles and the return value should be displayed in main() AFTER displaying the sorted numbers in the array.

double standardDeviation( double array[], int numberOfValues )

This function will calculate the standard deviation of the values in an array of doubles.

This function takes two arguments: the first argument is an array of doubles that holds the numbers to be used in the calculation, and the second argument is an integer that holds the number of values to use in the calculation. The function returns a double: the standard deviation of the values in the array of doubles.

The standard deviation is calculated as follows:

where

?( x2 ) is the sum of the numbers squared

(? x)2 is the square of the sum of the numbers

n is the number of values

--------------------------------------------------------------------------------------------

The following is the extra output for the runs of the program from earlier in the assignment write-up.

Run 1 using srand(0)

First Array: Smallest Value: 1.286 Largest Value: 147.794 Average: 71.140 Standard Deviation: 45.737 Second Array: Smallest Value: 0.545 Largest Value: 149.149 Average: 73.449 Standard Deviation: 43.368 

Run 2 using srand(time(0))

First Array: Smallest Value: 0.989 Largest Value: 148.563 Average: 76.127 Standard Deviation: 42.802 Second Array: Smallest Value: 3.745 Largest Value: 149.368 Average: 68.219 Standard Deviation: 47.113
(??) 2 ? x2) Standard deviation ? 1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!