Question

Please Help!(Write a C++ program Only):- The attached file has a number of records giving US...

Please Help!(Write a C++ program Only):- The attached file has a number of records giving US state names, populations, and number of Federal electors. The fields are delimited by spaces. The first field is a single integer giving the number of states that follow.

Guidelines:- 1)Read the first integer and use it to allocate dynamic arrays to contain the state name and the state population. 2) Read in the population data. The electors field is not used. 3) Calculate the mean of the population of the states. 4) Calculate the standard deviation of the population of the states. 5) List the states whose populations are within 0.5 standard deviations of the mean popluation. 6) Calculate the percentage of state that satisfy this criteria. 7) Cleanup.

Formulas

Mean

Variance

open parentheses sum from i equals 1 to n of left parenthesis m e a n minus p subscript i right parenthesis squared close parentheses divided by n

Standard Deviation

square root of v a r i a n c e end root

The assignment is to calculate and display some statistics about the state population data, as shown below.

Output:-

US Population Statistics as of 2015 (51 states)

  Total population: 321418820
  Population mean:6302329.8
  Population standard deviation:7130151.4
States whose population is within .5 standard deviations of the mean:
  New_Jersey
  Virginia
  ...
  Nevada
____% of the states are within .5 standard deviations of the mean population

file name is "us-pop-by-state-with-electors-2015.txt" I couldn't able to upload so I pasted below:-

California 39144818 55
Texas 27469114 38
Florida 20271272 29
New_York 19795791 29
Illinois 12859995 20
Pennsylvania 12802503 20
Ohio 11613423 18
Georgia 10214860 16
North_Carolina 10042802 15
Michigan 9922576 16
New_Jersey 8958013 14
Virginia 8382993 13
Washington 7170351 12
Arizona 6828065 11
Massachusetts 6794422 11
Indiana 6619680 11
Tennessee 6600299 11
Missouri 6083672 10
Maryland 6006401 10
Wisconsin 5771337 10
Minnesota 5489594 10
Colorado 5456574 9
South_Carolina 4896146 9
Alabama 4858979 9
Louisiana 4670724 8
Kentucky 4425092 8
Oregon 4028977 7
Oklahoma 3911338 7
Connecticut 3590886 7
Iowa 3123899 6
Utah 2995919 6
Mississippi 2992333 6
Arkansas 2978204 6
Kansas 2911641 6
Nevada 2890845 6
New_Mexico 2085109 5
Nebraska 1896190 5
West_Virginia 1844128 5
Idaho 1654930 4
Hawaii 1431603 4
New_Hampshire 1330608 4
Maine 1329328 4
Rhode_Island 1056298 4
Montana 1032949 3
Delaware 945934 3
South_Dakota 858469 3
North_Dakota 756927 3
Alaska 738432 3
Washington_DC 672228 3
Vermont 626042 3
Wyoming 586107 3

Thank you so much for helping.

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

Here is the code for the first few parts.....

#include <iostream>
#include <iomanip>
#include <cmath>
#include <fstream>
using namespace std;
long totalCalc(long *population, int size)
{
    long total = 0;
    for(int i = 0; i < size; i++)
        total += *(population + i);
    return total;  
}
int main()
{
    ifstream fin;
    fin.open("USPopulationByStateWithElectors2015.txt");
    if(!fin.is_open())
    {
       cout << "Unable to open the file." << endl;
       return 0;
    }
    //1)Read the first integer and use it to allocate dynamic arrays to contain the
    //   state name and the state population.
    int numOfStates;
    fin >> numOfStates;
    string *states = new string[numOfStates];
    long *population = new long[numOfStates];
    int *electors = new int[numOfStates];
    //2) Read in the population data. The electors field is not used.
    for(int i = 0; i < numOfStates; i++)
        fin >> *(states + i) >> *(population + i) >> *(electors + i);
    cout << "US Population Statistics as of 2015 (" << numOfStates << " states)" << endl;
    long totalPopulation = totalCalc(population, numOfStates);
    cout << "Total population: " << totalPopulation << endl;
    //3) Calculate the mean of the population of the states.
    double mean = totalPopulation / (double)numOfStates;
    cout << "Population mean: " << fixed << setprecision(2) << mean << endl;
    double stdDev = 0;
    for(int i = 0; i < numOfStates; i++)
        stdDev += pow((*(population + i) - mean), 2);   //Sum of (number - average) whole square.
    stdDev = sqrt(1/(double)numOfStates * stdDev);
    cout << "Population standard deviation: " << stdDev << endl;
    cout << "States whose population is within .5 standard deviations of the mean:" << endl;
    for(int i = 0; i < numOfStates; i++)
        if(abs(*(population + i) - stdDev) <= 0.5)
            cout << *(states + i) << endl;     
}

And the output screenshot is:

Terminal Shell Edit View Window Help 1.18 GB (D < >し 令동啦) 99% E ฏิเ Sun 9 Apr 01:45 ANANDA KUMAR THUMMAPUDI E Currently Open

Sorry. I didn't got your points for the last 2 points. Please be clear, or give some formula, for that.

Add a comment
Know the answer?
Add Answer to:
Please Help!(Write a C++ program Only):- The attached file has a number of records giving US...
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
  • Chapter 2, Section 3, Exercise 107 Percent Obese by State Computer output giving descriptive statistics for...

    Chapter 2, Section 3, Exercise 107 Percent Obese by State Computer output giving descriptive statistics for the percent of the population that is obese for each of the 50 US states, from the USStates dataset, is given in the table shown below. Since all 50 US states are included, this is a population, not a sample Descriptive Statistics: Obese Variable N N MeanSE Mean StDev Minimum Median3 Maximum Obese 50 028.766 0.4763.369 21.300 26.375 29.400 31.150 35.100 Percent of the...

  • I need help with deviation questions. My data: 8 2 2 5 8 6 2 3...

    I need help with deviation questions. My data: 8 2 2 5 8 6 2 3 5 7 5 2 2 2 5 4 8 1 2 1 1 5 1 5 5 0 0 7 7 11 5 9 3 2 5 2 5 1 4 3 5 3 4 3 7 7 6 1 0 3 2 6 4 1 1 4 4 4 5 0 5 4 1 7 3 3 3 0 5 2 4 2...

  • need help really bad! dont understand 0 Consider the following set of ungrouped Sample data. Answer...

    need help really bad! dont understand 0 Consider the following set of ungrouped Sample data. Answer parts Athrough 4 4 4 4 0 2 1 5 6 10 (A) Find the mean and standard deviation of the grouped sample data x=cType an integer or a decimal) (Type an integer or decimal rounded to three decimal places as needed (B) What proportion of the measurement lies within 1 standard deviation of the mean Win 2 standard deviations? Wandard deviations? Ils of...

  • R problem 1: The reason that the t distribution is important is that the sampling distribution...

    R problem 1: The reason that the t distribution is important is that the sampling distribution of the standardized sample mean is different depending on whether we use the true population standard deviation or one estimated from sample data. This problem addresses this issue. 1. Generate 10,000 samples of size n- 4 from a normal distribution with mean 100 and standard deviation σ = 12, Find the 10,000 sample means and find the 10,000 sample standard deviations. What are the...

  • Means and SDs For each part, compare distributions (1) and (2) based on their means and...

    Means and SDs For each part, compare distributions (1) and (2) based on their means and standard deviations. You do not need to calculate these statistics; simply state how the means and the standard deviations compare. You will need to look at Exercise 1.47 in OpenIntro Statistics to answer these questions There are two correct answers to each part below; select them both. 1.47 Means and SDs. For each part, compare distributions (1) and (2) based on their means and...

  • can someone please explain how to do this? I am very confused and it is due...

    can someone please explain how to do this? I am very confused and it is due tomorrow. Directions: Write the null and alternate hypothesis, determine the appropriate t-test for cach of the following problems, decide upon a decision rule, draw the rejection region, and write a statement that describes the relationship the researcher is entitled to make. (You may use Excel to calculate means, variance and standard deviation). 11 An investigator believes that families in Virginia have more children on...

  • .wileyplus.com/euugerynuymanium S Lock, Statistics: Unlocking the Power of Data, 2e Help System Announcements ctice Assignment Gradebook...

    .wileyplus.com/euugerynuymanium S Lock, Statistics: Unlocking the Power of Data, 2e Help System Announcements ctice Assignment Gradebook ORION nment PRINTER VER Chapter 2, Section 3, Exercise 107 Percent Obese by State Computer output giving descriptive statistics for ti percent of the population that is obese for each of the 50 US states, from the USStates dataset, is given in the table shown below. Since included, this is a population, not a sample. Descriptive Statistics: Obese Variable N N* Mean SE Mean...

  • Answer the number 3 and 4 question Worksheet 2: Chapters 3 and 8 (Normal Distributions; Sampling)...

    Answer the number 3 and 4 question Worksheet 2: Chapters 3 and 8 (Normal Distributions; Sampling) Math 243, Sunmmer '19, Vargas (c) (3.5) What percentage of all MLB players are shorter than your team's shortest player, according to the Normal distribution? What about taller than your team's tallest player? 3. (3.4) Consider the N(73.7,2.3) distribution for the height in the population of all MLB players. (a) From the population, find the intervals of player heights within one standard deviation of...

  • 1.The two branches of statistics are (1.1) a) dependent and independent c) descriptive and inferential 2.When...

    1.The two branches of statistics are (1.1) a) dependent and independent c) descriptive and inferential 2.When we compute averages and standard deviations or graph data, we are b) population and sample d) ull and alternative workinq within a)descriptive statistics c) hypothesis testing 3. Which of the following groups is likely to have a lower standard deviation? b)inferential statistics d) statistical graphing (3.2) Group A: average heights of 13-year-old males Group B: average heights of 25-year old males a) Group A...

  • please Answer question 9 and 10 Question 4 answer is : The distribution is not normally...

    please Answer question 9 and 10 Question 4 answer is : The distribution is not normally distributed. Question 6 answer is : 80% Question 7 answer is : 92% Question 8 answer is : 98% Question: Using the computer (Excel), answer the following 10 questions: Assessing Normality Many times in statistics it is necessary to see if a set of data values is approximately normally dis- tributed. There are special techniques that can be used. One technique is to draw...

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