Question: Could anyone please help me with this C++ program? The United Nations provided 2009 Marital Status of Men and Women in the US (http://data.un.org/DocumentData.aspx?id=322). Write

Could anyone please help me with this C++ program?

The United Nations provided 2009 Marital Status of Men and Women in the US (http://data.un.org/DocumentData.aspx?id=322).

Write a program to analyze the marital status of the combined total of men and women in the US. The categories being analyzed is as follows:

Single Men

Married Men

Widowed Men

Divorced Men

Separated Men

Single Women

Married Women

Widowed Women

Divorced Women

Separated Women

The program first reads headings, categories and the statistics from the file and saves them into three arrays:

Create a one-dimensional string array of the tableHeadings.

Create a one-dimensional string array Categories to store the different categories.

Create a (parallel) two-dimensional double array CatPerc to store percentage in each category. This array has 11 columns of the percentages in each age group.

The program then retrieves the percentages from the array CalcPerc, calculates average percentage of the combined men and women in each category. (Ignore age range 60-64 in calculation)

i.e. (Single Men Average + Single Women Average)/2.0

where Single Men Average = (Sum of Single Men Percentages) / 10.0 and Single Women Average = (Sum of Single Women Average)/10.0 .

Use the table below to assign the representation code to each combined men and women average in each combined category.

Average

Representation Code

>= 40

H - High

>= 25

N - Normal

< 25

L -Low

The program must contain at least the following functions:

(1) A function read_data to read and store data into tableHeadings, categories and calcPerc arrays.

(2) A function analyze_stats to calculate the combined men and women averages, determine the Representation Code, get the number of High, Normal and Low Representation Codes, find the highest and lowest average of all combined categories.

(3) A function display_results to display the results.

Here is the text file that is needed: "Survey.txt"

United States of America

Sex MaritalStatus 15-19 20-24 25-29 30-34 35-39 40-44 45-49 50-54 55-59 60-64 65+

Men Single 98.5 87.0 61.1 35.0 22.5 18.4 17.0 12.5 7.9 0.0 4.4

Men Married 0.8 11.0 34.1 56.6 65.2 66.1 65.6 69.3 74.0 0.0 73.2

Men Widowed 0.1 0.0 0.0 0.0 0.2 0.5 0.9 1.2 2.3 0.0 12.9

Men Divorced 0.1 0.8 3.1 6.1 9.2 12.4 14.1 14.5 13.7 0.0 8.3

Men Separated 0.5 1.2 1.7 2.3 2.9 2.7 2.4 2.5 2.1 0.0 1.2

Women Single 97.2 77.4 46.3 26.3 16.4 13.1 11.5 10.0 7.1 0.0 4.0

Women Married 1.7 18.8 45.5 61.9 67.0 67.5 65.6 65.4 65.2 0.0 43.0

Women Widowed 0.1 0.3 0.3 0.6 1.1 1.4 2.8 3.8 8.2 0.0 41.3

Women Divorced 0.2 1.5 5.1 8.0 11.4 13.7 16.6 17.4 17.4 0.0 10.7

Women Separated 0.8 2.0 2.9 3.3 4.2 4.2 3.5 3.4 2.1 0.0 1.1

Use the following driver to test your functions:

#include

#include

#include

#include

using namespace std;

const int NUM_HEADINGS = 13;

const int NUM_CATEGORIES = 10;

const int NUM_COMBINED_PERC = 5;

const int NUM_PERCENTAGE = 11;

void read_data(ifstream &input, string tableHeadings[], string categories[],

double catPerc[][NUM_PERCENTAGE]);

void analyze_stats(double catPerc[][NUM_PERCENTAGE], double combinedPerc[],

int &high_cnt, int &norm_cnt, int &low_cnt,

double &highest,double &lowest);

void display_results(string categories[],double combinedPerc[], int high_cnt, int norm_cnt,

int low_cnt, double highest, double lowest);

int main()

{

string tableHeadings[NUM_HEADINGS];

string categories[NUM_CATEGORIES];

double catPerc[NUM_CATEGORIES][NUM_PERCENTAGE];

double combinedPerc[NUM_COMBINED_PERC];

double highest = 0.0, lowest = 0.0;

char representativeCode[NUM_COMBINED_PERC];

int high_cnt = 0, norm_cnt = 0, low_cnt = 0;

ifstream inFile;

inFile.open("Survey.txt", ios::in);

if (!inFile.is_open())

{

cout << "Error: Cannot open file...Exiting." << endl;

system("pause");

exit(0);

}

//Read the input file and populate the arrays.

read_data(inFile, tableHeadings, categories,catPerc);

//Use the populated category percentage array to derive the combined percentage,

//count of high, norm and low representation codes.

analyze_stats(catPerc,combinedPerc,high_cnt,norm_cnt,low_cnt,highest,lowest);

//Display the results

display_results(categories,combinedPerc, high_cnt,norm_cnt,low_cnt,highest,lowest);

inFile.close();

system("pause");

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!