Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In c++ If we define the median of a sequence as a number so that exactly as many elements come before it in the sequence

In c++

If we define the median of a sequence as a number so that exactly as many elements come before it in the sequence as come after it, fix the program in 4.6.3 so that it always prints out a median. Hint: A median need not be an element of the sequence.

4.6.3:

// compute mean and median temperatures

int main() {

vector temps; // temperatures

for (double temp; cin>>temp; ) // read into temp

temps.push_back(temp); // put temp into vector

// compute mean temperature:

double sum = 0;

for (int x : temps) sum += x;

cout << "Average temperature: " << sum/temps.size() << ' ';

// compute median temperature:

sort(temps); // sort temperatures

cout << "Median temperature: " << temps[temps.size()/2] << ' ';

}

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

Data Management Databases And Organizations

Authors: Richard T. Watson

3rd Edition

0471418455, 978-0471418450

More Books

Students also viewed these Databases questions

Question

1. How will you, as city manager, handle these requests?

Answered: 1 week ago

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago