1answer.
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]
3 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]3 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
50POINTS
maxonik [38]

Answer:

Ensure that all material and energy inputs and outputs are as inherently safe and benign as possible. Minimize the depletion of natural resources. Prevent waste. Develop and apply engineering solutions while being cognizant of local geography, aspirations, and cultures.Green engineering is the design, commercialization, and use of processes and products that minimize pollution, promote sustainability, and protect human health without sacrificing economic viability and efficiency.The goal of environmental engineering is to ensure that societal development and the use of water, land and air resources are sustainable. This goal is achieved by managing these resources so that environmental pollution and degradation is minimized.

Explanation:i helped

7 0
3 years ago
Read 2 more answers
आर्किटेक्ट ईन्जिनियरले भवन वा दरबार आदिको निर्माण गर्दा विशेष ध्यान दिने ३ वटा पक्षहरुको नाम लेख।
Varvara68 [4.7K]

Answer:

Explanation:

What does that mean

8 0
3 years ago
A 55-μF capacitor has energy ω (t) = 10 cos2 377t J and consider a positive v(t). Determine the current through the capacitor.
mart [117]

Given :

Capacitor , C = 55 μF .

Energy is given by :

\omega(t)=10cos^2 (377t)\ J .

To Find :

The current through the capacitor.

Solution :

Energy in capacitor is given by :

\omega=\dfrac{Cv^2}{2}\\\\v=\sqrt{\dfrac{2\omega}{C}}\\\\v=\sqrt{\dfrac{2\times 10cos^2 (377t)}{55\times 10^{-6}}}\\\\v=cos(337t)\sqrt{\dfrac{2\times 10}{55\times 10^{-6}}}\\\\v=603.02\ cos( 337t)

Now , current i is given by :

i=C\dfrac{dv}{dt}\\\\i=C\dfrac{d[603.02cos(337t)]}{dt}\\\\i=-55\times 10^{-6}\times 603.03\times 337\times sin(337t)\\\\i=-11.18\ sin(337t)

( differentiation of cos x is - sin x )

Therefore , the current through the capacitor is -11.18 sin ( 377t).

Hence , this is the required solution .

6 0
3 years ago
A one-dimensional slab without heat generation has a thickness of 20 mm with surfaces main- tained at temperatures of 275 K and
vlada-n [284]

Answer:

a) 512.5 KW/m2

b) 40.75 KW/m2

c) 2 KW/m2

Explanation:

Given data;

T_2 = 325 K

T_1 = 275 K

dx = 0.20 mm

a) for aluminium   K = 205 W/m k

heat flux = k \frac{dt}{dx}

               = 205 \frac{325 - 275}{0.02}

               = 512.5 KW/m2

b) for AISI 316 stainless steel

k = 16.3 W/ m k

heat flux = k \frac{dt}{dx}

               = 16.3 \frac{325 - 275}{0.02}

               = 40.75 KW/m2

C) for Concrete

k = 0.8 W/ m k

heat flux = k \frac{dt}{dx}

               = 0.8 \times \frac{325 - 275}{0.02}

               = 2 KW/m2

6 0
3 years ago
Column arrays: Transpose a row array Construct a row array countValues with elements 1 to endValue, using the double colon opera
White raven [17]

Answer:

Matlab code with step by step explanation and output results are given below

Explanation:

We have to construct a Matlab function that creates a row vector "countValues" with elements 1 to endValue. That means it starts from 1 and ends at the value provided by the user (endValue).  

function countValues = CreateArray(endValue)

% Here we construct a row vector countValues from 1:endValue

     countValues = 1:endValue;

% then we transpose this row vector into column vector

     countValues = countValues';

 end

Output:

Calling this function with the endValue=11 returns following output

CreateArray(11)

ans =

    1

    2

    3

    4

    5

    6

    7

    8

    9

   10

   11

Hence the function works correctly. It creates a row vector then transposes it and makes it a column vector.

7 0
3 years ago
Other questions:
  • Two metallic terminals protrude from a device. The terminal on the left is the positive reference for a voltage called vx (the o
    8·1 answer
  • A 1-m long, thin symmetric airfoil is placed at a free stream. Calculate the drag force for the wind speed of 150 m/s. Assume th
    7·1 answer
  • Is it true or false that sometimes people except certain risks in exchange for other benefits
    13·1 answer
  • How do people eat with there noses shut
    12·2 answers
  • 2+2 = 900000000000000000000000000000000000
    7·1 answer
  • Question in image. Question from OSHA.
    11·2 answers
  • 2. The speaker argues that more data allow us to see new things. Think about your favorite hobby—skateboarding, listening to mus
    8·2 answers
  • How many volts of alternating current passes through the electrolytic capacitor
    5·1 answer
  • Who wants to do a zoom
    10·2 answers
  • FOR DARKEND1<br><br>÷<br><br><br>try copy and paste​
    5·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!