There are at least four mistakes that I see: first, the join '',@table that is in your BEGIN_TEXT...END_TEXT block it going to fall outside the table, since it is not containied in a row() , and second, row($teststr)
is going to produce a row with only one entry because you passsing it a
list of only one element (the string whose contents is a bunch of
numbers separated by commas). The third error is that you haven't
cleared out the @table array before you start pushing the
answer rules onto it, so the table array will include all the numbers
and commas as well as the answer rules. Finally, the begintable(horiz_center=>'yes') is not right. The begintable() command needs a column count as its parameter, not an attribute list. You need to use begintable($total) instead. There is no way to get centered values using begintable() .
You can solve the last problem by adding @table = (); before the loop that pushes answer rules.
You could overcome the first problem by using row(@table) instead of join '', @table .
For the second problem, however, you can't use the string you created
earlier, you need the array, so you probably want to keep a second
array, one for the numbers, and one for the answer rules.
Here's my version of the problem: $total = 5;
for ($j = 1; $j <= $total; $j++) { push @row1, $j; push @row2, ans_rule(5); push @cmp, num_cmp($j); }
BEGIN_TEXT \{ begintable(5) . row('Subject','Mean','Stand. dev.','score','z score') . row(1, 1, 1, 'grade1', 'A') . row(2, 2, 2, 'grade2', 'B') . row(3, 3, 3, 'grade3', 'C') . row(4, 4, 4, 'grade4', 'D') . endtable() \} $PAR \{ begintable($total) . row(@row1) . row(@row2) . endtable() \} END_TEXT
ANS(@cmp);
Here I have made several changes in addition to those discussed above. First, I got rid of the needless $i loop, and run the $j loop starting at 1 rather than 0 (avoiding the need for $k ). Then I create three separate arrays, all in the same loop: @row1 contains the numbers used in row 1 of the table, @row2 contains the answer rules for row 2, and @cmp contains the answer evaluators to be submitted to ANS() .
This puts all the information for one column together in one place,
rather than scattered all over the problem, so it is more likely that
the answer checkers and answers will match in the end.
Next, I put the table calls into a single \{...\} pair to make it easier to read. The commands are separated by ". ",
which is the string concatenation operator, so the combined result of
all the table calls is the result. Note that the second table is made
from the row of numbers and the row of answer rules.
The ANS() call takes the array of answer checkers and assigns them each to an answer blank.
I mentioned above that begintable()
does not allow you to center the values. It also doesn't give you
control over the spacing or other attributes of the table, and it
always produces HTML tables with borders. There is an alternative set
of table macros in unionTables.pl in the Union College union_problib/macros
directory. The macros there give you more control over the spacing and
alignment of the entries, and can produce tables without borders. Read
the comments in that file to see how to control the macros.
Here is a version of the problem using those macros: loadMacros( "unionMacros.pl", "unionTables.pl" );
$total = 5;
for ($j = 1; $j <= $total; $j++) { push @row1, $j; push @row2, ans_rule(5); push @cmp, num_cmp($j); }
%ropts = (separation=>0); # options for the table rows sub BOLD {$BBOLD.(shift).$EBOLD};
BEGIN_TEXT \{ BeginTable(border => 1, padding => 3, spacing => 2) . AlignedRow([BOLD('Subject'),BOLD('Mean'),BOLD('Stand. dev.'), BOLD('score'),BOLD('z score')],%ropts) . AlignedRow([1, 1, 1, 'grade1', 'A'],%ropts) . AlignedRow([2, 2, 2, 'grade2', 'B'],%ropts) . AlignedRow([3, 3, 3, 'grade3', 'C'],%ropts) . AlignedRow([4, 4, 4, 'grade4', 'D'],%ropts) . EndTable() \} $PAR \{ BeginTable(spacing => 3) . AlignedRow([@row1],%ropts) . AlignedRow([@row2],%ropts) . EndTable() \} END_TEXT
ANS(@cmp);
Here the rows are generated as before. We use options to BeginTable() to specify the border size and extra spacing around the entries in the table, and AlignedRow() to get centered rows. The %ropts hash is used to give the same parameters to all rows; in this case, we override the default row separation. Note that while row() takes an array of enteries, AlignedRow() (and Row() , not used here) takes a reference to an array of entries, followed by options that affect the row. That's why the square brackets are used.
I also put the table headings in bold, to make them stand out more. That is done through the BOLD() command defined just before the first table.
Anyway, hope that clears things up for you.
Davide
<| Post or View Comments |>
|