Question

C++. You are working for the census bureau and you need to write a program to...

C++. You are working for the census bureau and you need to write a program to do the following:


A). Count the number of people in each of the following age groups: 0-18 infant, 18-29 young, 29 - 50 middle aged, 50 - 69 old, 69 - and older really old. Report the number of people in each age group. (use some random data for test).


B). They need some statistics regarding the distribution of ages. Write a program to read in a number of ages. Compute the average age (mean) and the mode i.e. the age that occurs most frequently (be careful, some of the ages might be the same). Ages should be read in as integers, the average should be a real number. Also calculate the standard deviation using the formula:
Square root of 1 under and n over sigma-summation x sub i squaredd slash n minus left-parenthesis i under and n over sigma-summation x sub i slash n right-parenthesis square


0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is your C++ Program:

C++ Program:

#include<iostream>

#include<stdio.h>

#include<conio.h>

#include<math.h>

using namespace std;

void main()

{

int RandomData[]={10,5,20,45,20,66,25,31,20,70}; //Random Data

int infant=0,young=0,middle=0,old=0,older=0; //To store count

int n,freq,count=0,high=0; //to store mode and other

double stdDev,mean,sum=0; //to store stdDev mean and sum

for(int i=0;i<(sizeof(RandomData)/sizeof(RandomData[0]));i++) //loop to count

{

if(RandomData[i]>0&&RandomData[i]<=18)

infant++;

else if(RandomData[i]>18&&RandomData[i]<=29)

young++;

else if(RandomData[i]>29&&RandomData[i]<=50)

middle++;

else if(RandomData[i]>50&&RandomData[i]<=69)

old++;

else if(RandomData[i]>69)

older++;

}

double first=0,sec=0; //to store result of stdDev formula first and second part

for(int i=0;i<(sizeof(RandomData)/sizeof(RandomData[0]));i++) //loop to calculate mean mode and stdDev

{

n=RandomData[i];

count=0;

for(int j=0;j<(sizeof(RandomData)/sizeof(RandomData[0]));j++)

{

if(n==RandomData[j])

count++;

}

if(high<count)

{

freq=RandomData[i];

high=count;

}

first+=(pow((RandomData[i]),2)/(sizeof(RandomData)/sizeof(RandomData[0])));

sec+=RandomData[i]/(sizeof(RandomData)/sizeof(RandomData[0]));

sum+=RandomData[i];

}

mean=sum/(sizeof(RandomData)/sizeof(RandomData[0]));

stdDev=sqrt(first-pow((sec),2));

/*------Printing Result-----*/

cout<<"\nCount:\nInfant: "<<infant<<"\nYoung: "<<young<<"\nMiddle: "<<middle;

cout<<"\nOld: "<<old<<"\nOlder: "<<older;

cout<<"\n\nMean: "<<mean<<"\nMode: "<<freq<<"\nStandard Deviation: "<<stdDev;

/*-----------XXXX-------------*/

getch();

}

ScreenShot of Output And Code:

I hope this solves your problem

Comment if you have any problem in above code

And please give it a thumbs up if it solved your problem :)

Add a comment
Know the answer?
Add Answer to:
C++. You are working for the census bureau and you need to write a program to...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • C++ ONLY The question is - The US Census Bureau gathers population information and aggregates it...

    C++ ONLY The question is - The US Census Bureau gathers population information and aggregates it at the city, county and state level. A research project on population distribution in the Southeast US has acquired a data file from the Census Bureau that contains the populations of each county in Mississippi (MS) and Florida (FL). For this research project write a program that calculates the average county population for these two states. Each line in the Census Bureau data file...

  • The U.S. Census Bureau collects data on the ages of married people. Suppose that eight married...

    The U.S. Census Bureau collects data on the ages of married people. Suppose that eight married couples are randomly selected and have the ages given in the following table. Determine the 90% confidence interval for the true mean difference between the ages of married males and married females. Let d=(age of husband)−(age of wife). Assume that the ages are normally distributed for the populations of both husbands and wives in the U.S.: Husband: 75 41 62 38 53 27 59...

  • The Census Bureau groups data on households into census tracts, where each census tract has a total population of about 4,000 residents. Census tracts should be divided so that the households in the c...

    The Census Bureau groups data on households into census tracts, where each census tract has a total population of about 4,000 residents. Census tracts should be divided so that the households in the census tracts share certain characteristics, such as economic status. Even though most tracts are around 4,000 residents, there is some variability, which is the focus of this lab. In practice, census tracts usually have a population between 1,200 and 8,000 people. I just need help with the...

  • need help with these Question 7 (20 points) The U.S. Census Bureau conducts a study to...

    need help with these Question 7 (20 points) The U.S. Census Bureau conducts a study to determine the time needed to complete the short form. The Bureau surveys 200 people. The sample mean is 8.2 minutes. There is a known standard deviation of 2.2 minutes. The population distribution is assumed to be normal. (a) (5 points) Construct a 90% confidence interval for the population mean time to complete the forms. (b) (5 points) calculate the error bound. (c) (5 points)...

  • Python help. Write a program that asks the user to enter a person's age. The program...

    Python help. Write a program that asks the user to enter a person's age. The program should display a message indicating whether the person is an infant, a child, a teenager, or an adult. Following are the guidelines: If the person is 2 year old or less, he or she is an infant. If the person is older than 2 year, but younger than 13 years, he or she is a child. If the person is at least 13 years...

  • using matlab 3. Write a script that will read the ages vector.dat file created in the...

    using matlab 3. Write a script that will read the ages vector.dat file created in the previous problem. - the script will print the number of persons in the group - the script will print the maximum and minimum ages in the group - the script will compute and print the "average age" The script should return something like: The file contains the ages of a group of 50 people The maximum and minimum ages in the group are 10...

  • 1.20 Table 1.9 give the age distribution of the U.S. population in 1890 and 2010 (projected): A) What age class contained the median age in 1890? B) What age class contained the median age in 2010? C...

    1.20 Table 1.9 give the age distribution of the U.S. population in 1890 and 2010 (projected): A) What age class contained the median age in 1890? B) What age class contained the median age in 2010? C) compare the median ages and comment on the change in age distributions .22 The Los Angeles Times ofsep contains the following statement: "According to Table 1.9 U.S. Population in 1890 and 2010 (projected) 30-39 40-49 50-59 9.5% 14.2% 60-69 4% 9.5% 70+ Age...

  • C++ Program Loop

    Final task 1.pngKids need more calcium as they get older to support their bones.Sample Runs for task 1 :Welcome to the program that shows the amount of daily calcium needed for kids age 1-18. Kids need more calcium as they get older to support their growing bones. Amount needed for kids has been listed below:- Kids 1 to 3 years old need 1000mg of calcium a day. - Kids 9 to 18 years old need 1300mg of calcium a day.Design an algorithm...

  • [JAVA} Thanks in advance for your help! Write a program that asks the user to type...

    [JAVA} Thanks in advance for your help! Write a program that asks the user to type in ages. They will type a negative age when they finish entering the ages. The program will print out the average of all of the ages and the oldest age entered. It should end with a newline. Sample output #1 Type a negative for age to exit Enter your age: 21 Enter your age: 22 Enter your age: 21 Enter your age: -8 The...

  • //Done in C please! //Any help appreciated! Write two programs to write and read from file...

    //Done in C please! //Any help appreciated! Write two programs to write and read from file the age and first and last names of people. The programs should work as follows: 1. The first program reads strings containing first and last names and saves them in a text file (this should be done with the fprintf function). The program should take the name of the file as a command line argument. The loop ends when the user enters 0, the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT