answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
hoa [83]
2 years ago
7

In this lab, you complete a C++ program that uses an array to store data for the village of Marengo. The program is described in

Chapter 8, Exercise 5, in Programming Logic and Design. The program should allow the user to enter each household size and determine the mean and median household size in Marengo. The program should output the mean and median household size in Marengo. The file provided for this lab contains the necessary variable declarations and input statements. You need to write the code that sorts the household sizes in ascending order using a bubble sort and then prints the mean and median household size in Marengo. Comments in the code tell you where to write your statements.1. Open the source code file named HouseholdSize.cpp using Notepad or the text editor of your choice.2. Write the bubble sort.3. Output the mean and median household size in Marengo.4. Save this source code file in a directory of your choice, and then make that directory your working directory.5. Compile the source code file HouseholdSize.cpp.6. Execute the program with the following input and record the output: Household sizes: 4, 1, 2, 4, 3, 3, 2, 2, 2, 4, 5, 6Here is the Householdsize.cpp file information:// HouseholdSize.cpp - This program uses a bubble sort to arrange up to 300 household sizes in// descending order and then prints the mean and median household size.// Input: Interactive.// Output: Mean and median household size.#include #include using namespace std;int main(){ // Declare variables. const int SIZE = 300; // Number of household sizes int householdSizes[SIZE]; // Array used to store 300 household sizes int x; int limit = SIZE; int householdSize = 0; int pairsToCompare; bool switchOccurred; int temp; double sum = 0; double mean = 0; int medianIndex = 0; // Input household size cout << "Enter household size or 999 to quit: "; cin >> householdSize; // Fill an array with household sizes - the maximum households = 300 x = 0; while(x < limit && householdSize != 999) { // Place value in array. householdSizes[x] = householdSize; // Calculate total of household sizes using the sum variable x++; // Get ready for next input item. cout << "Enter household size or 999 to quit: "; cin >> householdSize; } // End of input loop. // set the limit to x // calulate the mean household size by dividing the sum by the limit // Use one of your sort routines to sort the Array so that the house sizes are in ascending order // Print the mean // Set medianIndex = (limit-1)/2 // Print the median found at householdSizes[medianIndex] return 0;} // End of main function
Engineering
1 answer:
sladkih [1.3K]2 years ago
6 0

Answer:

The edited program is as follows

// Program to calculate mean and median of numbers

// Program is written in C++

#include<iostream>

//This program uses a bubble sort to arrange up to 300 household sizes in

// descending order and then prints the mean and median household size.

// Input: Interactive.

// Output: Mean and median household size.

using namespace std;

int main(){

// Declare variables.

const int SIZE = 300;

// Number of household sizes

int householdSizes[SIZE];

// Array used to store 300 household sizes

int x;

int limit = SIZE;

int householdSize = 0; int temp; double sum = 0; double mean = 0; int medianIndex = 0;

// Input household size

cout << "Enter household size or 999 to quit: ";

cin >> householdSize;

// Fill an array with household sizes - the maximum households = 300

x = 0;

while(x < limit && householdSize != 999) {

// Place value in array.

householdSizes[x] = householdSize;

// Calculate total of household sizes using the sum variable

sum+ = householdSizes[x];

x++;

// Get ready for next input item.

cout << "Enter household size or 999 to quit: ";

cin >> householdSize;

}

// End of input loop.

// set the limit to x

// calculate the mean household size by dividing the sum by the limit

mean = sum/x;

cout<<"Mean = "<<mean;

// Sort array

for(i=0; i<(SIZE-1); i++)

{

for(j=0; j<(SIZE-i-1); j++)

{

if(householdSizes[j]>householdSizes[j+1])

{

temp= householdSizes[j];

householdSizes[j] = householdSizes[j+1];

householdSizes[j+1] = temp;

}

}

}

// Set medianIndex

int index = (limit-1)/2;

//Print the median found at householdSizes[medianIndex]

cout<<"Median: "<<householdSizes[medianIndex];

return 0;

}

// End of main function

You might be interested in
Your roommate wants to learn about organizational chart. You can tell her that these charts can tell you all of these about an o
mars1129 [50]

Answer:

Control mechanisms

Explanation:

Organizational chart of any company will give details of different aspects of the company such as the major sub-units of the organization with the names of team leaders for different sub-units, it can also give you the span of control and the division of work within the company. However, the chart can't show you control mechanisms of different departments.

4 0
2 years ago
Suppose we store a relation R (x,y) in a grid file. Both attributes have a range of values from 0 to 1000. The partitions of thi
leva [86]

Answer:

For (a) The total number of buckets from the given query for the relation is 25 buckets (b) the nearest neighboring query is (80, 200) (80, 150), (100, 150), (120,150) and (120, 200)

Explanation:

From the question stated, we need to define what a Grid file is

Grid File it is a structure of data that are used to divide the total space into a grid non-periodic, where set of point (small) are defined by more than one cells of the grid.

(a)Finding buckets for the query

The relation is divided into two parts which ranges from 0 to 1000, the first part is partitioned in every 20 units, at 20, 40, 60 etc; a second part is partitioned into every 50 units at 50, 100, 150 etc.

The total number of buckets from the given query for the relation is 25 buckets

(b)Finding the closest point or nearest point

The closest point discovered in the distance is little above 15

These points are are the points closer to the point target (110, 205) which can be found in five neighboring rectangles with left corners lower is stated as follows:

(80, 200) (80, 150), (100, 150), (120,150) and (120, 200)

3 0
2 years ago
Which of the following is NOT true about hydraulic valves? A. Directional control valves determine the path of a fluid in a give
Lelechka [254]

Answer: Option D is not true of hydraulic valves. A hydraulic valve is a device that can change the opening degree of liquid flow path

Explanation:

The pilot check valve allows flow of liquid in one direction and blocks flow in the opposite direction

5 0
2 years ago
A fatigue test was conducted in which the mean stress was 46.2 MPa and the stress amplitude was 219 MPa.
sleet_krkn [62]

Answer:

a)σ₁ = 265.2 MPa

b)σ₂ = -172.8 MPa

c)Stress\ ratio =-0.65

d)Range = 438 MPa

Explanation:

Given that

Mean stress ,σm= 46.2 MPa

Stress amplitude ,σa= 219 MPa

Lets take

Maximum stress level = σ₁

Minimum stress level =σ₂

The mean stress given as

\sigma_m=\dfrac{\sigma_1+\sigma_2}{2}

2\sigma_m={\sigma_1+\sigma_2}

2 x 46.2 =  σ₁ +  σ₂

 σ₁ +  σ₂ = 92.4 MPa    --------1

The amplitude stress given as

\sigma_a=\dfrac{\sigma_1-\sigma_2}{2}

2\sigma_a={\sigma_1-\sigma_2}

2 x 219 =  σ₁ -  σ₂

 σ₁ -  σ₂ = 438 MPa    --------2

By adding the above equation

2  σ₁ = 530.4

σ₁ = 265.2 MPa

-σ₂ = 438 -265.2 MPa

σ₂ = -172.8 MPa

Stress ratio

Stress\ ratio =\dfrac{\sigma_{min}}{\sigma_{max}}

Stress\ ratio =\dfrac{-172.8}{265.2}

Stress\ ratio =-0.65

Range = 265.2 MPa - ( -172.8 MPa)

Range = 438 MPa

8 0
2 years ago
During normal operation, an electrical component experiences a constant rate of ohmic dissipation ini g = 0.01 W that causes the
Llana [10]

Answer:

Check the explanation

Explanation:

Kindly check the attached image below for the step by step explanation to your answer.

4 0
2 years ago
Other questions:
  • Tin atoms are introduced into a FCC copper crystal, producing an alloy with a lattice pa- rameter of 3.7589 x 10-8 cm and a dens
    8·1 answer
  • A petrol engine produces 20 hp using 35 kW of heat transfer from burning fuel. What is its thermal efficiency, and how much powe
    14·1 answer
  • An optical mouse originally cost $31.85. Before it was removed from the store, it underwent the following changes in price. 27%
    8·2 answers
  • A 5-cm-diameter shaft rotates at 4500 rpm in a 15-cmlong, 8-cm-outer-diameter cast iron bearing (k = 70 W/m·K) with a uniform cl
    10·1 answer
  • Which statement concerning symbols used on plans is true?
    10·1 answer
  • What ratio between differential gain and common-mode gain is called​
    9·1 answer
  • Complete the following sentence.
    5·1 answer
  • The BARO sensor informs the PCM about changes in weather and ____________________.
    14·1 answer
  • 140-character statement that completes this sentence: I pledge to not text and drive because...
    12·1 answer
  • 1. A _____ is applied to a wall or roof rafters to add strength and keep the building straight and plumb.
    9·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!