Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

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
expand button
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.
expand button
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
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education