Question: Use C++ for this question. And MAKE SURE YOUR PROGRAM WORKS PLEASE. The US Census Bureau gathers population information and aggregates it at the city,
Use C++ for this question. And MAKE SURE YOUR PROGRAM WORKS PLEASE.
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 has the following structure
NJ Burlington 451336
The first field (starting at the first character) contains the two letter code for the state. The second field is the name of the county, and the third field is the 2010 population. The fields are separated by a single tab character. The input data lines are in no particular state order. Don't make any assumptions about the number of lines in the file. A data file for testing your program can be found here.
Write a program that asks the user for the input file's name. Open the file and read each line. Sum and average the appropriate values. Once all of the input lines are read, write out the average county population for each state, both to the console and to an output file. Format your output so that a user can understand the meaning of the calculation, i.e. don't just output "state average". The average value should also be formatted to have 1 decimal place using the fixed decimal format. So you should perform floating point arithmetic operations. Your program should have the following functions:
A function that opens the input and output files and sets the output of the floating-point number to one decimal place in a fixed decimal format.
A function that initializes the variables needed in the main program. (hint: you will need to use pass by reference in this function.)
A function that adds a county population to the current sum for a state.
A function that calculates the average county population for a state. (hint: this function should return a floating point value.)
A function that outputs the relevant results to the console and into the output file.
Do not use global variables in this program. Use the appropriate parameters to pass information in and out of the functions.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
