Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

If you choose to do a Bubble Sort instead of a Selection Sort: Create a double value to hold the value of the i variable

If you choose to do a Bubble Sort instead of a Selection Sort:

Create a double value to hold the value of the i variable when you need to swap the values, call it temp and remember local variables need to be initialized, so set its value to zero

Use i for the outer for loop counter and j for the inner for loop counter

outer for loop: for int i equals zero, i less than numElements -1, i plus plus

inner for loop: for int j equals i plus one, j less than numElements, j plus plus

In your code, make sure you use the private data member numElements and do not use the vector::size() or vector::capacity() or you get a warning about a signed/unsigned mismatch. In other words, your code should NOT contain any instances of the call to: elements.size() or elements.capacity()

inner for loop test: if elements j is less than elements i swap values, there is no else if the values are in the correct order, nothing needs to happen

When the if statement returns true, you will swap the 2 values, so:

assign temp the vector elements i value

assign the vector elements i the vector elements j value

assign the vector elements j the temp value

end the inner for loop and end the outer for loop

int Stats::size() const

Note: returns the number of elements in the vector.

Note: The number of elements is the same as the size of the vector.

double Stats::mean() const

Note: returns the absolute average

create a double called sum, remember local variables need to be initialized, set value to zero

use a for loop to process the elements in the vector, less than number of elements

add each vector element to the double sum you created above

when number of elements / size > 0 return the sum divided by the size else return 0.0

double Stats::max() const

Note: returns the largest number in the population

If vector is not sorted, sort it

Return the last element in the vector

double Stats::min() const

Note: returns the smallest number in the population

If vector is not sorted, sort it

Return the first element in the vector

double Stats::median() const

Note: this function returns the value of the middle element in the vector, so divide the vector size by two and return the data value at that index

If vector is not sorted, sort it

Return the element at the middle location in the vector [numElements/2]

void Stats::display() const

Note: Print all numbers

In a for loop, counter less than number of elements, display each element followed by a space.

Output:

/*

Student Name, CIS 127, Assignment 10.3

Enter file name: numbers.data Elements before sort: 5 1 6 2 3 8 9 4 7 10 Elements after sort: 1 2 3 4 5 6 7 8 9 10 Statistics for a set of tests Size: 10 Mean: 5.5 High: 10 Low: 1 Median: 6 Statistics for a set of tests Size: 13 Mean: 5.92308 High: 19 Low: -2 Median: 5 Elements after sort: -2 1 2 3 4 5 5 6 7 8 9 10 19 Press any key to continue . . . */

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions