Question: The primary purpose of this program is exercising your knowledge of complex function calls and nested looping statements. You are to read in a series
The primary purpose of this program is exercising your knowledge of complex function calls and nested looping statements. You are to read in a series of numbers into an array of fixed length not to exceed 100 numbers. Your program will stop accepting input when a negative number is input. Once the negative number is input, your program will sort the numbers using a unique sorting algorithm called the Bubble Sort and output the sorted array and the average (mean). The negative number is not included in the list and average.
Program Specifications:
Your program will prompt the user to enter in from 2 to 100 positive integers.
You can assume the user will input at least two numbers and no more than 100.
Input will be stopped when a negative number is entered.
Your program will store the numbers in a fixed size integer array of 100 items.
You must keep track of the number of values entered.
Once the numbers are entered sort them using the Bubble Sort algorithm provided.
You must not use Global Variables
You must have functions that pass values as parameters and return a value. (The provided Bubble Sort does not count)
The output will include the array sorted in ascending order with the average printed out at the end. The average will be a floating point number with 4 digits or precision and showing trailing zeros.
Bubble Sort: Copy the following code including the comments into your program to sort the numbers.
// ******************************************************** // * Name: BubbleSort * // * Description: Accepts an array as a parameter of * // * type integer and sorts the array using the * // * standard Bubble Sort algorithm. Compares * // * adjacent values on a pass through the array. * // * if an exchange is made it goes through the array * // * again. * // * Author: Dr. David A. Gaitros * // * Date: November 25th, 2022 * // * Copyright: For use for educational purposes only. * // * Students must include these comments in the code * // * when using this routine. * // ********************************************************
void BubbleSort(int a[MAXARRAY],const int size) { bool swapped= true; int holder; while(swapped) { swapped=false; for (int index=0; index
Compute Average:
Sum all values into a floating point variable. Divide the sum by the number of numbers in the array. Maker sure to convert all values to floating point numbers and return a floating point number. Simple mean.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
