Question: Write a C++ Program that sorts an array through bubble sort by swapping values and then finding median of that sorted array. Most importantly write

Write a C++ Program that sorts an array through bubble sort by swapping values and then finding median of that sorted array. Most importantly write your code in the following parts.

  1. Make a function Swap( ) that takes address of the two integers variables as arguments (pointers) and swap those two variables.
  2. Make a function BubbleSort( ) which sorts an integer type array into ascending order. The function BubbleSort( ) takes the array and its size as argument.

It uses the above function swap while sorting to swap two array elements by passing those array elements to swap function.

  • Make a function Median() that takes an array and its size as arguments. Then it calls the above function BubbleSort() to sort the array. After sorting it will find the mean of that sorted array through following formual.
  • Write main program. Take the values of array in it from user. Call only the function named median( ) from main and pass it the array and its size.

3

1

4

1

5

9

2

6

5

Formula for Median of an array in C++

When size of array is even: Median = arr[size/2];

When size of array is odd: Median = ( arr[ size/2 ]+arr[ size/(2+1)] ) / 2.0;

Remember arrays index start from 0.

Step by Step Solution

3.45 Rating (155 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Solution 1 int swapint a int b int main int a 10 b 2... View full answer

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 Programming Questions!