//Before calculating the median, we must sort the 1/array. //1f the array is even... if (numbers.size() X 2 -- 0) //Get the mid index int mid - numbers.size() / 2; //Get the two numbers in the mid. (mid is the the right most middle number.) //Get mid anid mid- 1. double numl - numbers(mid]; double num2 - numbers(mid - 1]; T/Calculate the average of the two middle num return //the average.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
double median()
//Before calculating the median, we must sort the
//array.
//If the array is even...
if (numbers.size() % 2 -- 0)
{
//Get the mid index
int mid - numbers.size()/ 2;
//Get the two numbers in the mid. (mid is the i
ndex of the right most middle number.)
//Get mid ar'd mid - 1
double numl - numbers [mid];
double num2 = numbers [mid - 1];
//Calculate the average of the two middle numbe
rs and return
//the average.
return average_mid;
else
//Determine the median index and return the
//number at the median.
int mid - numbers.size() /2;
return numbers [mid];
}
//Sorts the array in ascending order.
void BubbleSort)
for (int i - 0; i < numbers.size(); i++)
{
bool swapped false;
for (int j - 0; j< numbers.size() - i - 1; j++
{
if (numbers[j] > numbers[j + 1]
swap(numbers[), number
s[j + 11);
swapped - true;
if (swapped -- false)
return;
}
private:
//Used only in Bubble Sort. Ignore...
void swap(double& a, double& b)
{
double temp- a;
a - b;
b - temp;
};
int main)
VCreate a StatSet variable called "s".
//Add the number "55" to the StatSet "s".
//Calculate the median of the numbers.
return 0;
PIC CO
Transcribed Image Text:double median() //Before calculating the median, we must sort the //array. //If the array is even... if (numbers.size() % 2 -- 0) { //Get the mid index int mid - numbers.size()/ 2; //Get the two numbers in the mid. (mid is the i ndex of the right most middle number.) //Get mid ar'd mid - 1 double numl - numbers [mid]; double num2 = numbers [mid - 1]; //Calculate the average of the two middle numbe rs and return //the average. return average_mid; else //Determine the median index and return the //number at the median. int mid - numbers.size() /2; return numbers [mid]; } //Sorts the array in ascending order. void BubbleSort) for (int i - 0; i < numbers.size(); i++) { bool swapped false; for (int j - 0; j< numbers.size() - i - 1; j++ { if (numbers[j] > numbers[j + 1] swap(numbers[), number s[j + 11); swapped - true; if (swapped -- false) return; } private: //Used only in Bubble Sort. Ignore... void swap(double& a, double& b) { double temp- a; a - b; b - temp; }; int main) VCreate a StatSet variable called "s". //Add the number "55" to the StatSet "s". //Calculate the median of the numbers. return 0; PIC CO
#include <iostream>
#include <vector>
using std::cout;
using std::vector;
class StatSet
{
private:
HCreate a vector of doubles that is called "numbers."
public:
//Nothing to do in the constructor.
StatSet()
}
// Add a new number to the set.
vòid add_num(double num)
{
}
double mean()
{
//Sum up the values and return the average.
double sum = 0;
//Write a loop that would iterate through the vector.
sum += numbers[i];
return sum / numbers.size();
}
double median()
//Before calculating the median, we must sort the
//array.
Transcribed Image Text:#include <iostream> #include <vector> using std::cout; using std::vector; class StatSet { private: HCreate a vector of doubles that is called "numbers." public: //Nothing to do in the constructor. StatSet() } // Add a new number to the set. vòid add_num(double num) { } double mean() { //Sum up the values and return the average. double sum = 0; //Write a loop that would iterate through the vector. sum += numbers[i]; return sum / numbers.size(); } double median() //Before calculating the median, we must sort the //array.
Expert Solution
steps

Step by step

Solved in 5 steps with 3 images

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education