Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function in C++ called findMedian that takes two parameters - an array of int and the size of the array. The function should

Write a function in C++ called findMedian that takes two parameters - an array of int and the size of the array. The function should return the median of the array, which will require sorting the array (you can use the built-in sort function from the examples). This will change the original array, but that's okay for this assignment. If you're not familiar with calculating the median, please look that up. Remember that it's different for odd and even groups of values. If you are testing your code by calling it from a different file, remember to have a function prototype for findMedian in that file. PLEASE PROVIDE INT MAIN() TEST SEPARATE FROM THE REST OF THE CODE

The file must be named: findMedian.cpp.

Example of using the built-in sort function

image text in transcribed

This program first initializes an array of ints. Next we use the built in sort function, which requires that you include . It takes two arguments - a pointer to the start of the array, and a pointer to the end of the array (arrived at here through pointer arithmetic). Afterward, when the array is printed out, the elements will be in ascending numeric order.

For the following projects (and all future projects in this course):

Do not include a main method in the files you submit - just the definitions of the assigned functions. I will compile your code with my own main method for testing, and there can only be one main method in a program. You will of course need to have a main method for testing purposes - just make sure you comment it out (or delete it) before submitting your file.

Do not use any global variables. Global variables and their drawbacks are discussed on pages 357-9 of the textbook. If the assignment description doesn't specify a return value for a function, then it should have a return type of void.

#include int mainCO int array[] = {23, 5, -10, 0, 0, 321, 1, 2, 99, 30); int size = 10; std::sort(array, array +size); for (int i = 0; 1

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

Step: 3

blur-text-image

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

ISBN: 321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

What are the companys strengths and competitive advantages?

Answered: 1 week ago