######################################################################## ## DESCRIPTION ## A WeBWorK problem that asks students to construct a frequency distribution ## table and answer questions on it. ## WeBWorK problem written by JoAnne Taormina, ## ENDDESCRIPTION ## ## KEYWORDS('frequency distribution table') ## ## Author('JoAnne Taormina') ## Institution('Nassau Community College') ######################################################################## DOCUMENT(); loadMacros( "PGstandard.pl", "MathObjects.pl", "PGgraphmacros.pl", "PGchoicemacros.pl", "unionTables.pl", "weightedGrader.pl", ); install_weighted_grader(); $refreshCachedImages=1; # make sure we're in the context we want Context("Numeric"); # the data @data = (); @sorted = (); for($i = 0; $i < 40; $i ++) { $data[$i] = random(100, 150, 1); } @sorted = num_sort(@data); # number of classes $numclasses = 8; # the table data $table_start = begintable(5); $table_row[0] = row( "Classes", "Frequencies", "Class Marks", "Class Boundaries" , "Relative Percentages"); for ( $i = 1; $i <=$numclasses; $i++ ) { $table_row[$i] = row( ans_rule(5) . "-" . ans_rule(5), ans_rule(10), ans_rule(10), ans_rule(5) . "-" . ans_rule(5), ans_rule(19) . "%" ); } $table_end = endtable(); $smallest = $sorted[0]; $largest = $sorted[39]; if(($largest - $smallest)%$numclasses==0) { $class_width = ceil(( $largest - $smallest )/$numclasses) + 1; } else { $class_width = ceil(( $largest - $smallest )/$numclasses); } TEXT(beginproblem()); Context()->texStrings; BEGIN_TEXT (a) Create a frequency distribution table with $BBOLD 8 classes $EBOLD from the following data. $BR$BR Include classes, frequencies, class marks, class boundaries, and relative percentages. $BR$BR Relative percentages should be expressed as percents $BBOLD but do not put a % symbol in your answer or you will be marked wrong.$EBOLD For example, 12.25 should be entered instead of 12.25%. Do not round any quantities. $BR $BR \[ $data[0], \ $data[1], \ $data[2], \ $data[3], \ $data[4], \ $data[5], \ $data[6], \ $data[7], \ $data[8], \ $data[9] \] \[ $data[10], \ $data[11], \ $data[12], \ $data[13], \ $data[14], \ $data[15], \ $data[16], \ $data[17], \ $data[18], \ $data[19] \] \[ $data[20], \ $data[21], \ $data[22], \ $data[23], \ $data[24], \ $data[25], \ $data[26], \ $data[27], \ $data[28], \ $data[29] \] \[ $data[30], \ $data[31], \ $data[32], \ $data[33], \ $data[34], \ $data[35], \ $data[36], \ $data[37], \ $data[38], \ $data[39] \] $BR $BR $BCENTER $table_start $table_row[0] $table_row[1] $table_row[2] $table_row[3] $table_row[4] $table_row[5] $table_row[6] $table_row[7] $table_row[8] $table_end $ECENTER END_TEXT Context()->normalStrings; for ($j=0; $j<$numclasses; $j++) { $lower_limit = $smallest + $class_width*$j; $class_low_limit = Formula("$lower_limit"); WEIGHTED_ANS( $class_low_limit->cmp(),1.5179 ); $upper_limit = $lower_limit+$class_width-1; $class_high_limit = Formula("$upper_limit"); WEIGHTED_ANS( $class_high_limit->cmp(),1.5179 ); for ($k=0; $k<40; $k++){ if($data[$k]>=$lower_limit && $data[$k]<=$upper_limit){ $frequency++; } } $class_frequency = Formula("$frequency"); WEIGHTED_ANS ($class_frequency->cmp(),1.5179); $class_mark = ($lower_limit + $upper_limit) / 2; $class_mark = Formula("$class_mark"); WEIGHTED_ANS ($class_mark->cmp(),1.5179); $lower_class_boundary = $lower_limit - .5; $class_boundary_low = Formula("$lower_class_boundary"); WEIGHTED_ANS($class_boundary_low->cmp(),1.5179); if($j == 2){ $start_part_b = $lower_limit; } if($j==3){ $start_part_c = $lower_limit; } $upper_class_boundary = $upper_limit + .5; $class_boundary_high = Formula("$upper_class_boundary"); WEIGHTED_ANS( $class_boundary_high->cmp(),1.5179); if($j == 5){ $end_part_b = $upper_limit; } if($j==4){ $end_part_d = $upper_limit; } $relative_percentage = ($frequency / 40)*100; if($j>=3){ $answer_part_c+=$relative_percentage; } if($j>=2 && $j<=5){ $answer_part_b+=$relative_percentage; } if($j<=4){ $answer_part_d+=$relative_percentage; } $relative_percentage = Formula("$relative_percentage"); WEIGHTED_ANS($relative_percentage->cmp(),1.5179); $frequency = 0; } $answer_part_b = Formula("$answer_part_b"); WEIGHTED_ANS($answer_part_b->cmp(),5); $answer_part_c = Formula("$answer_part_c"); WEIGHTED_ANS($answer_part_c->cmp(),5); $answer_part_d = Formula("$answer_part_d"); WEIGHTED_ANS($answer_part_d->cmp(),5); BEGIN_TEXT $BR$BR (b) What is the percentage of data values that fall between \{ $start_part_b \} and \{ $end_part_b \}, inclusive? $BITALIC Express your answer as a percent without the % symbol. $EITALIC \{ans_rule(5)\}% $BR$BR (c) What is the percentage of data values are \{ $start_part_c \} or greater? $BITALIC Express your answer as a percent without the % symbol. $EITALIC \{ans_rule(5)\}% $BR$BR (d) What is the percentage of data values that are \{ $end_part_d \} or less? $BITALIC Express your answer as a percent without the % symbol. $EITALIC $BR \{ans_rule(5)\}% $ECENTER $BR$BR END_TEXT ENDDOCUMENT();