Asked by Andrew
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 readers. The participants have written for 1 to 40 books each, and target reader's ages range from 0 through 16. Design a program that continuously accepts the number of books written until a sentinel value is entered, and then display a list of how many participants have written each number of books (1 through 40).
Answers
Answered by
Steve
you can probably adapt this little perl ditty to your needs. Other languages may be more verbose, however.
my %authors,%ages,%counts;
while (<>) {
last unless $_;
my ($count,$age,$name) = split(/\s+/,$_,3);
$authors{$name} = [$count,$age];
$ages{$age}++;
$counts{$count}++;
}
foreach my $c (1..40) {
printf "%2d: %3d\n",$c,$counts{$c};
}
my %authors,%ages,%counts;
while (<>) {
last unless $_;
my ($count,$age,$name) = split(/\s+/,$_,3);
$authors{$name} = [$count,$age];
$ages{$age}++;
$counts{$count}++;
}
foreach my $c (1..40) {
printf "%2d: %3d\n",$c,$counts{$c};
}
Answered by
TERA
can this be written in pseudoode?
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.