|
The static graphics example
To obtain this problem
WARNINGS µ¦å{h
Enter this code:
{viewSource(setMAAtutorial/staticgraphicsexample/staticgraphicsexample.pg)}
Comments:
- Set
$showPartialCorrectAnswers to 0 so that students can't tell which matches are wrong.
-
pictID is perl's version of a multi-dimensional array. Strictly speaking @pictID is a list of references (pointers) to arrays, each of which has a number of entries. $pictID[1] is a pointer to an array, and $pictID[1][3] chooses an item in that array (the 4th item since we are counting from 0).
- The way the code is set up the first entry,
$pictID[0] is blank, $pictIC[1] points to an array with entries numbered from 0 to 7, and so forth.
- GIF files containing the appropriate graphs have already been created and placed in the directory containing the static graphics PG template. The numbering convention is meant to try to keep from giving the answer away, while still allowing the instructor to do some error checking. Note the center numbers in each label.
- The variable
$pictSet, chosen as a number between 1 and 3, chooses a picture set. This set is placed in the matching list object $ml, along with the matching answers. David Eck's program xFunctions (for the Macintosh, and now available in java) was used to draw the graphs and the transformations of the graphs.
- Next we want to print the graphs in a table. The standard print function for matching list objects prints the answers in a vertically spaced, ordered list which would take up too much space, so we write a new print function (or subroutine) for the matching list object called
format_graphs. This print function outputs a string of IMG tags for the chosen graphs, separated by the # symbol. (The specs for the matching list require that the output of the print function be a string and not an array.)
-
$ml->rf_print_a(~~&format_graphs); installs the new print function in the matching list object $ml. (The convenction rf_... means that we require a reference to a function. ) &format_graphs is a function, and ~~&format_graphs is a value which is a reference to that function. Recall that in PG we use ~~ rather than \ as in ordinary perl, because backslashes are reserved for TeX like commands for formatting mathematics.
- Next comes the text of the problem, including the graph of the original function F
{ image($pictSet) } and the questions involving the transformation of F { $ml -> print_q } .
- Next we print the table, with just one row of pictures. The command
split("\#",$ml->print_a() ) splits the string of answers at the # symbol into a list, which is what the macro row requires.
- The answers are letters and are placed in the
ANS function by $ml->ra_correct_ans(). The ra_... convention, means that the ouput is a reference to an array.
|