/ 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

C++ Programming: From Problem Analysis to Program Design
8th Edition
ISBN:9781337102087
Author:D. S. Malik
Publisher:D. S. Malik
Chapter8: Arrays And Strings
Section: Chapter Questions
Problem 16PE
icon
Related questions
Question
100%

// 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 <iostream>#include <string>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

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Array
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.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr
Programming Logic & Design Comprehensive
Programming Logic & Design Comprehensive
Computer Science
ISBN:
9781337669405
Author:
FARRELL
Publisher:
Cengage
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT