programming

posted by .

Daily Life Magazine wants an analysis of the demographic characteristics of its readers. The Marketing Department has collected reader survey records containing the age, gender, marital status, and annual income of readers. Design an application that accepts reader data and produces a count of readers by age groups as follows: under 20, 20-29, 30-39, 40-49, and 50+

  • programming -

    Here's a little perl program which does the job. You can format and sort the output as needed.


    my $agegroup;
    while ($_ = <DATA>) {
    print "Enter age, sex, status, income: $_";
    my $age = (split)[0];
    my $ag = int($age/10);
    $ag = 1 if $ag < 2; # count 0-10 as teens (under 20)
    push @{$agegroup->{$ag}}, $_;
    }
    close DATA;
    foreach my $ag (sort keys %$agegroup) {
    my $agk = ($ag<2) ? "Under 20" : sprintf("%d-%d",10*$ag,10*$ag+9);
    my $cnt = @{$agegroup->{$ag}};
    print "$agk: $cnt\n";
    foreach my $rec (@{$agegroup->{$ag}}) {
    print " $rec";
    }
    }


    Here is the output from a sample run:


    Enter age, sex, status, income: 46 M M 37000
    Enter age, sex, status, income: 17 M D 36000
    Enter age, sex, status, income: 31 M S 164000
    Enter age, sex, status, income: 41 F D 295000
    Enter age, sex, status, income: 51 M M 198000
    Enter age, sex, status, income: 15 M M 55000
    Enter age, sex, status, income: 66 M S 73000
    Enter age, sex, status, income: 50 M D 161000
    Enter age, sex, status, income: 62 M S 96000
    Enter age, sex, status, income: 28 M D 232000
    Enter age, sex, status, income: 46 M D 92000
    Enter age, sex, status, income: 48 M S 186000
    Enter age, sex, status, income: 37 M D 100000
    Enter age, sex, status, income: 51 F D 193000
    Enter age, sex, status, income: 20 F D 202000
    Enter age, sex, status, income: 66 F M 264000
    Enter age, sex, status, income: 28 F S 280000
    Enter age, sex, status, income: 20 M M 33000
    Enter age, sex, status, income: 39 F S 280000
    Enter age, sex, status, income: 27 F S 187000
    Enter age, sex, status, income: 61 F M 272000
    Enter age, sex, status, income: 46 F M 41000
    Enter age, sex, status, income: 31 M S 305000
    Enter age, sex, status, income: 31 M M 145000
    Enter age, sex, status, income: 67 M M 313000
    Enter age, sex, status, income: 35 F M 235000
    Enter age, sex, status, income: 34 M S 106000
    Enter age, sex, status, income: 47 M D 182000
    Enter age, sex, status, income: 65 M S 90000
    Enter age, sex, status, income: 48 M S 273000
    Under 20: 2
    17 M D 36000
    15 M M 55000
    20-29: 5
    28 M D 232000
    20 F D 202000
    28 F S 280000
    20 M M 33000
    27 F S 187000
    30-39: 7
    31 M S 164000
    37 M D 100000
    39 F S 280000
    31 M S 305000
    31 M M 145000
    35 F M 235000
    34 M S 106000
    40-49: 7
    46 M M 37000
    41 F D 295000
    46 M D 92000
    48 M S 186000
    46 F M 41000
    47 M D 182000
    48 M S 273000
    50-59: 3
    51 M M 198000
    50 M D 161000
    51 F D 193000
    60-69: 6
    66 M S 73000
    62 M S 96000
    66 F M 264000
    61 F M 272000
    67 M M 313000
    65 M S 90000

Respond to this Question

First Name
School Subject
Your Answer

Similar Questions

  1. math

    Scenario: Regression equations are created by modeling data, such as the following: Sales = (Cost Per Item × Number of Items) – Constant Charges In this equation, constant charges may be rent, salaries, or other fixed costs. This …
  2. Statistic

    Submit your answers to the following questions using the ANOVA source table below. The table depicts a two-way ANOVA in which gender has two groups (male and female), marital status has three groups (married, single never married, …
  3. Computers

    Daily Life Magazine wants an analysis of the demographic characteristics of its readers. The Marketing Department has collected reader survey records containing the age, gender, marital status, and annual income of readers. Design …
  4. c+=

    true life magazine wants an analysis of the demographic characteristics of readers in c++ the marketing department has collectedreader survey records containing the age , gender , marital status ,and annual income of readers the data …
  5. Analyzing with ANOVA

    Submit your answers to the following questions using the ANOVA source table below. The table depicts a two-way ANOVA in which gender has two groups (male and female), marital status has three groups (married, single never married, …
  6. Answers check and help!

    d. Calculate the mean square for 1) gender, 2) marital status, 3) interaction between gender and marital status, and 4) error or within variance. e. Calculate the F ratio for 1) gender, 2) marital status, and 3) interaction between …
  7. PROGRAMMING

    design a program for the following. Registration workers at a conference for authors of children's book have collected data about conference participants, including the number of book each author has written and the target age of their …
  8. Computers

    Need help creating pseudocode for the following. Registration workers at a conference for authors of children's books have collected data about conference participants, including the number of books each author has written and the …
  9. statistics

    As part of a data base on new births at a hospital some variables recorded are the age of the mother, marital status of the mother (single, married, divorced), weight of the baby, and gender of the baby. Of these variables A. age, …
  10. English 1

    Why do some readers choose to join reader groups?

More Similar Questions