Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

DESIGN CRITERIA: You must use a double array in this program to hold the numbers

ID: 3643887 • Letter: D

Question

DESIGN CRITERIA: You must use a double array in this program to hold the
numbers; this array may not be global in scope. You must use three functions; one
to INPUT the values into the array, one to SORT the array (in desired order), and a
third to OUTPUT the sorted array. The array must be passed to the SORT, INPUT,
and OUTPUT functions by use of a pointer. This is a requirement for sign-off. The
SORT function you write should use a bubble-sort algorithm.

PROGRAM INPUT: The ten numbers to be sorted.

PROGRAM OUTPUT: The sorted list of elements, and the average, maximum, and
minimum element values.

heres what i have so far

#include <iostream>
#include <cstdlib>
#include <ctime>
//This function builds the array
//Asks the user for values to be stored in the array
void buildArray(int arr[], int size) {
int n;
double num;

for(int i = 0; i < size; ++i)
{
cout <<"enter a number to be sorted : ";
cin >> num;
arr[i] = num;
}


}
//This function displays the elements of the array
void displayArray(int arr[], int size) {
for(int i = 0; i < size; ++i)
cout << arr[i] << " ";
}

// this function swaps the values stored in num1 and num2
void swap(int *num1, int *num2)
{


int temp = *num1;
*num1 = *num2;
*num2 = temp;
}
//this function bubble sorts the data
void bubbleSort(int arr[], int size) {
for(int i = 0; i < size-1; ++i)
for(int j = i+1; j < size; ++j)
if (arr[i] > arr[j]) {
swap(&arr[i], &arr[j]);
displayArray(arr, size);
cout << endl;
}
}

int main()//This function is where everything comes together and wehre the final array is displayed
{
const int size = 10;
int numbers[size];
buildArray(numbers, size);
cout << "Before sorting: ";
cout << endl;
displayArray(numbers, size);
cout << endl;
bubbleSort(numbers, size);
return 0;

fflush(stdin)
getchar()
}

Explanation / Answer

The program seems legit. Add the function to calculate the average, max and min int getMax(int []numbers,size){ return numbers[size-1]; } int getMin(int []numbers){ return numbers[0]; } double getAvg(int numbers[], int size){ int i=0, sum = 0; for(i=0;i