Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

he program is described in Chapter 8, Exercise 5, in Programming Logic and Design . The program should allow the user to enter each household

he 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 statements.

Instructions

  1. Make sure that the file HouseholdSize.cpp is selected and open.
  2. Write the bubble sort.
  3. Output the mean and median household size in Marengo.
  4. Execute the program by clicking the Run button and the bottom of the screen.
  5. Enter the following input, and ensure the output is correct. Household sizes: 4, 1, 2, 4, 3, 3, 2, 2, 2, 4, 5, 6 followed by 999 to exit the program.

sorttoarrangeupto300householdsizesin

//descendingorderandthenprintsthemeanandmedianhouseholdsize.

//Input:Interactive.

//Output:Meanandmedianhouseholdsize.

#include

#include

usingnamespacestd;

intmain()

{

//Declarevariables.

constintSIZE=300; //Numberofhouseholdsizes

inthouseholdSizes[SIZE]; //Arrayusedtostore300householdsizes

intx;

intlimit=SIZE;

inthouseholdSize=0;

intpairsToCompare;

boolswitchOccurred;

inttemp;

doublesum=0;

doublemean=0;

doublemedian=0;

//Inputhouseholdsize

cout<<"Enterhouseholdsizeor999toquit:";

cin>>householdSize;

//ThisistheworkdoneinthefillArray()function

x=0;

while(x

{

//Placevalueinarray.

householdSizes[x]=householdSize;

//Calculatetotalofhouseholdsizes

x++; //Getreadyfornextinputitem.

cout<<"Enterhouseholdsizeor999toquit:";

cin>>householdSize;

} //Endofinputloop.

//Findthemean

//ThisistheworkdoneinthesortArray()function

//ThisistheworkdoneinthedisplayArray()function

//Printthemean

//Findthemedian

//Printthemedian

return0;

}//Endofmainfunction

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

The Core Ios Developer S Cookbook Core Recipes For Programmers

Authors: Erica Sadun ,Rich Wardwell

5th Edition

0321948106, 978-0321948106

More Books

Students also viewed these Programming questions

Question

Why do bars offer free peanuts?

Answered: 1 week ago

Question

Name the seven operations and supply competitive dimensions.

Answered: 1 week ago