Question: At the completion of this module students will be able to: Writing a simple C++ program using pointers. Passing parameters by reference Compiling and linking

At the completion of this module students will be able to:

Writing a simple C++ program using pointers.

Passing parameters by reference

Compiling and linking

If Statements and Switch Statements

Embedded looping Statements

Standard Input and output

Variable Declaration

Converting integers to floating point numbers

Complex function calls

Common Algorithms

Good programming practices

Description:

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 a[index+1]) { holder=a[index]; a[index]=a[index+1]; a[index+1] = holder; swapped=true; } } } }

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.

Grading Criteria:

The program compiles. If the program does not compile no further grading can be accomplished. Programs that do not compile will receive a zero.

(25 Points) The program executes without exception and produces output. The grading of the output cannot be accomplished unless the program executes.

(25 Points) The program produces the correct output.

(10 Points) Read in the array properly and prints out the list.

(10 Points) List is sorted in ascending order

(5 Points) The mean (average) is calculated properly and as a floating point number.

(25 Points) Program Specifications are followed

(5 Points) Prompts the user for a string of numbers;

(5 Points) Input stops on a negative number, The negative number is not stored.

(5 Points) No Global Variable used. Global constant of the maximum number of array elements .

(5 Points) Bubble sort used

(5 Points) At least one function is used passing parameters and one that returns a value.

(10 Points)The program is documented (commented) properly. The bubble sort includes the comments from the assignment write-up. Any code used from the book , class or authorized source is commented to show where it was obtained.

( 5 Points) Average is 4 digits of precision showing trailing edge zeros.

( 5 Points) Use proper indentation

( 5 Points) Use proper naming standards.

Example Run:

Enter up to 100 positive numbers. \ A negative number will end the input:

4 23 43 56 1 23 98 123 6 4 2 89 -1 Sorted List 1 2 4 4 6 23 23 43 56 89 98 123 Mean is 39.3333

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!