CompoundProblem5

From WeBWorK
(Difference between revisions)
Jump to: navigation, search
(Created page with "<h2>Compound, MultiPart Problems Worked Sequentially</h2> <p style="background-color:#eeeeee;border:black solid 1px;padding:3px;"> <em>This is the PG code to create a problem...")
 
Line 2: Line 2:
  
 
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
 
<p style="background-color:#eeeeee;border:black solid 1px;padding:3px;">
<em>This is the PG code to create a problem with multiple parts that are displayed sequentially.  This is a newer way to write problems as in [[CompoundProblems|Compound Problems]], except this uses the macro compoundProblem5.pl. This creates a clean, folding interface for the problem, showing labels for each step. </em>
+
<em>This is the PG code to create a problem with multiple parts that are displayed sequentially.  This is a newer way to write compound (otherwise named "sequential" problems or more recently "scaffolded" problems. This method uses the macro compoundProblem5.pl to creates a clean, folding interface for the problem, showing labels for each step. See also [[CompoundProblems|CompoundProblems]]</em>
 
</p>
 
</p>
  
Line 25: Line 25:
 
   "parserPopUp.pl"  # Used in the popups
 
   "parserPopUp.pl"  # Used in the popups
 
);
 
);
#################
+
 
#Boiler Plate
+
#################
+
 
$scaffold = Scaffold();
 
$scaffold = Scaffold();
$isInstructor =  ($envir{effectivePermissionLevel} >= $envir{ALWAYS_SHOW_SOLUTION_PERMISSION_LEVEL});
+
#$isInstructor =  ($envir{effectivePermissionLevel} >= $envir{ALWAYS_SHOW_SOLUTION_PERMISSION_LEVEL});
 
$isInstructor=0;  # This variable changes what the user can see.
 
$isInstructor=0;  # This variable changes what the user can see.
 
INITIALIZE_SCAFFOLD('$scaffold');
 
INITIALIZE_SCAFFOLD('$scaffold');
Line 40: Line 38:
 
<p>
 
<p>
 
<b>Initialization:</b>
 
<b>Initialization:</b>
We need make no changes to the initialization section of the file.
+
First we have normal initialization inclusions. In this example we include <code>parserPopUp.pl</code> so that we can use that, and we need to include <code>compoundProblem5.pl</code> to enable the compound problem scaffold. After that, we have <code>$scaffold = Scaffold();</code> and <code>INITIALIZE_SCAFFOLD('$scaffold');</code> to do just that. We also create a variable that controls whether or not the user can view all parts of the problem without doing the entire thing. If one were to uncomment the line <code>#$isInstructor =  ($envir{effectivePermissionLevel} >= $envir{ALWAYS_SHOW_SOLUTION_PERMISSION_LEVEL});</code>, and comment out <code>$isInstructor=0;</code>, a professor should be able to view all parts of the problem at all times, but a student could not. How the code is currently presented, however, does not enable that flexibility, and requires that all users complete the required parts in order to view the next parts.  
In this example we include <code>parserPopUp.pl</code> so that we can use that.
+
 
</p>
 
</p>
 
</td>
 
</td>
Line 60: Line 57:
 
<p>
 
<p>
 
<b>Part 1 Setup:</b>
 
<b>Part 1 Setup:</b>
In this part of the problem, we do whatever we would normally  
+
For this method of creating a Compound Problem, we can have a setup section for every part of the problem. So, for the first part, we do what would normally be required for the problem. In this case, we define an answer (which is arbitrary just to demonstrate an example) and set <code>Context("Numeric");</code>.
do in setup that is required for the first section of the compound
+
problem. Here we set the context and define an answer.  
+
 
</p>
 
</p>
 
</td>
 
</td>
Line 89: Line 84:
 
<p>
 
<p>
 
<b>Part 1 Main Text:</b>
 
<b>Part 1 Main Text:</b>
The text for the question is broken down by section into the parts that we want the student to work sequentially.
+
Similarly, we have separate "TEXT" sections for each part of the compound problem, so we write what we would like to appear in the first part. However, before that, we must include
</p>
+
<p>
+
Note that if we have multiple answer blanks in the first part of the problem the numbers used to dereference the answer numbers must increment: e.g., if we had two true/false pop-ups, <code>$evenNum1</code> and <code>$evenNum2</code>, we would test for completeness of the first part of the problem with
+
 
</p>
 
</p>
 
<pre>
 
<pre>
 
+
DISPLAY_SECTION(  {  name=>"1: Set up problem",
 +
            canshow =>1,  #always true
 +
            iscorrect=>$scaffold->requireCorrect(1),
 +
            section=>1 #designates that this is the first section
 +
} , <<'END_SECTION');
 
</pre>
 
</pre>
 
+
<p>
 +
<code>name=>"1: Set up problem",</code> creates the label for the first part of the problem. <code>canshow =>1,</code> sets the problem up so that the first part of the problem is always open, available to view. This should (generally) always be done, unless you have a good reason to make the first part of the question not the first to do chronologically. For other parts of the problem, we would require that the previous parts be correct. <code>iscorrect=>$scaffold->requireCorrect(1),</code> designates that in order for this part of the question to be correct in total, the first and only answer (at this point) is correct. <code>section=>1 #designates that this is the first section</code> just says that this is the first part.
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 114: Line 111:
 
<b>Part 1 Answer evaluation and Solutions:</b>
 
<b>Part 1 Answer evaluation and Solutions:</b>
 
We've included the answer evaluators in the conditionals bracketing the display of the text, so they do not appear here. Solutions do, however, still show up here.
 
We've included the answer evaluators in the conditionals bracketing the display of the text, so they do not appear here. Solutions do, however, still show up here.
Note that each section can have a solution.
+
Note that each section can have a solution. The solution syntax is close to normal solution syntax, but we use <code>SECTION_SOLUTION({section=>1},<<'END_SOLUTION');</code> instead of <code>SOLUTION(EV3(<<'END_SOLUTION'));</code>. The rest of the solution follows as normal.
 
</p>
 
</p>
 
</td>
 
</td>
Line 162: Line 159:
 
<p>
 
<p>
 
<b>Part 2 Main Text:</b>
 
<b>Part 2 Main Text:</b>
Similar for how it was presented for part 1, but we set "canshow" to require that the first answer is correct. Also, we have two answers used in this part, so we set this part to be right when answers 2 and 3 are correct.
+
Again, we have another setup. This includes normal setup for the content of the part of the compound problem. We also have  
 
</p>
 
</p>
 
<pre>
 
<pre>
 
+
DISPLAY_SECTION( { name=>"2: Do something else",
 +
            canshow =>$scaffold->requireCorrect(1). " or $isInstructor",
 +
            iscorrect=>$scaffold->requireCorrect(2,3),
 +
            section=>2
 +
},  <<'END_SECTION');
 
</pre>
 
</pre>
 
+
<p>
 +
<code>name=>"2: Do something else",</code> again sets this as the label for the part of the problem. <code>canshow =>$scaffold->requireCorrect(1). " or $isInstructor",</code> designates that in order to show this part, one must have the first answer of the problem correct, or have <code>$isInstructor</code> true. <code>iscorrect=>$scaffold->requireCorrect(2,3),</code> makes it so that in order for this part of the question to be considered correct, on must have the second and third answer of the question correct. It should be noted that this is a continuing list of answers for the entire problem, not just for the section. The first part has one answer, but the second part has two, so we only set the second and third to count for the second part of the problem. Again, <code> section=>2</code> tells us that this is the second part of the question.
 +
</p>
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 185: Line 188:
 
<p>
 
<p>
 
<b>Part 2 Answer evaluation and Solutions:</b>
 
<b>Part 2 Answer evaluation and Solutions:</b>
We haven't included the answer checking yet, so it's done here. We also have another solution.
+
This is another solution one may have. Its syntax is identical to the first solution.
 
</p>
 
</p>
 
</td>
 
</td>
Line 208: Line 211:
 
<p>
 
<p>
 
<b>Part 3 Setup:</b>
 
<b>Part 3 Setup:</b>
The same thing as for the first two parts, but for whatever is in the third part.
+
Again, we have setup as we would as if the this part of the question were separate. We can, however, have problem-wide variables and functions.
 
</p>
 
</p>
 
</td>
 
</td>
Line 233: Line 236:
 
<p>
 
<p>
 
<b>Part 3 Main Text:</b>
 
<b>Part 3 Main Text:</b>
Here we have "canshow" require 2 and 3 be correct, because those were the  
+
This follows the same method as the second part's Main Text. We set <code>name=>"3: It's time for step 3!", </code> to be the name, <code>canshow =>$scaffold->requireCorrect(2,3). " or $isInstructor",</code> to indicate whether or not this part should be shown, <code>iscorrect=>$scaffold->requireCorrect(4), </code> to make it so this part of the question is considered correct if the fourth answer is marked right, and <code>section=>3</code> tells us this is the third part of the question.
answers blanks in the second part. We also mark this correct when the
+
fourth answer is right.
+
 
</p>
 
</p>
<pre>
 
 
</pre>
 
 
 
</td>
 
</td>
 
</tr>
 
</tr>
Line 278: Line 275:
 
<p>
 
<p>
 
<b>Finish:</b>
 
<b>Finish:</b>
Here we use some boiler plate actions to make sure the answers are processed and that the correct section is opened.
+
Here we use some boiler plate actions to make sure the answers are processed and that the correct section is opened. These process the question in its entirety and open the correct sections for the whichever part of the problem the user is on.
 
</p>
 
</p>
 
</td>
 
</td>

Revision as of 10:58, 1 July 2014

Compound, MultiPart Problems Worked Sequentially

This is the PG code to create a problem with multiple parts that are displayed sequentially. This is a newer way to write compound (otherwise named "sequential" problems or more recently "scaffolded" problems. This method uses the macro compoundProblem5.pl to creates a clean, folding interface for the problem, showing labels for each step. See also CompoundProblems

Problem Techniques Index

valign="top">
PG problem file Explanation
DOCUMENT();      
loadMacros(
   "PGstandard.pl",     # Standard macros for PG language
   "MathObjects.pl",    # Using MathObjects
    "compoundProblem5.pl",  #Required for the CompoundProblem
   "parserPopUp.pl"   # Used in the popups
);

$scaffold = Scaffold();
#$isInstructor =  ($envir{effectivePermissionLevel} >= $envir{ALWAYS_SHOW_SOLUTION_PERMISSION_LEVEL});
$isInstructor=0;   # This variable changes what the user can see.
INITIALIZE_SCAFFOLD('$scaffold');

TEXT(beginproblem());
$showPartialCorrectAnswers = 1; #normal initialization

Initialization: First we have normal initialization inclusions. In this example we include parserPopUp.pl so that we can use that, and we need to include compoundProblem5.pl to enable the compound problem scaffold. After that, we have $scaffold = Scaffold(); and INITIALIZE_SCAFFOLD('$scaffold'); to do just that. We also create a variable that controls whether or not the user can view all parts of the problem without doing the entire thing. If one were to uncomment the line #$isInstructor = ($envir{effectivePermissionLevel} >= $envir{ALWAYS_SHOW_SOLUTION_PERMISSION_LEVEL});, and comment out $isInstructor=0;, a professor should be able to view all parts of the problem at all times, but a student could not. How the code is currently presented, however, does not enable that flexibility, and requires that all users complete the required parts in order to view the next parts.

##############
#  Section 1
##############
Context("Numeric");
$ans = Compute("0");

Part 1 Setup: For this method of creating a Compound Problem, we can have a setup section for every part of the problem. So, for the first part, we do what would normally be required for the problem. In this case, we define an answer (which is arbitrary just to demonstrate an example) and set Context("Numeric");.

Context()->texStrings;
DISPLAY_SECTION(  {  name=>"1: Set up problem", 
             canshow =>1,  #always true
             iscorrect=>$scaffold->requireCorrect(1), 
             section=>1 $designates that this is the first section
} , <<'END_SECTION'); 

Here we have the first part of the question. 
This should be accessible as soon as the 
student sees the problem. Answer "0" to 
move to the next section.
$PAR
Answer is: \{SECTION_ANS($ans->cmp), $ans->ans_rule(15)\} 

END_SECTION

Part 1 Main Text: Similarly, we have separate "TEXT" sections for each part of the compound problem, so we write what we would like to appear in the first part. However, before that, we must include

DISPLAY_SECTION(  {  name=>"1: Set up problem", 
             canshow =>1,  #always true
             iscorrect=>$scaffold->requireCorrect(1), 
             section=>1 #designates that this is the first section
} , <<'END_SECTION'); 

name=>"1: Set up problem", creates the label for the first part of the problem. canshow =>1, sets the problem up so that the first part of the problem is always open, available to view. This should (generally) always be done, unless you have a good reason to make the first part of the question not the first to do chronologically. For other parts of the problem, we would require that the previous parts be correct. iscorrect=>$scaffold->requireCorrect(1), designates that in order for this part of the question to be correct in total, the first and only answer (at this point) is correct. section=>1 #designates that this is the first section just says that this is the first part. </td> </tr>

SECTION_SOLUTION({section=>1},<<'END_SOLUTION');
This is a sample solution for the section. It should be 
noted that you can have a solution for each section.

END_SOLUTION

<p> Part 1 Answer evaluation and Solutions: We've included the answer evaluators in the conditionals bracketing the display of the text, so they do not appear here. Solutions do, however, still show up here. Note that each section can have a solution. The solution syntax is close to normal solution syntax, but we use SECTION_SOLUTION({section=>1},<<'END_SOLUTION'); instead of SOLUTION(EV3(<<'END_SOLUTION'));. The rest of the solution follows as normal.

###############
#  Section 2
###############
Context()->normalStrings;
$ans = Compute("1");
$popup = PopUp(["Correct","Wrong","Extra Wrong"],"Correct");

Part 2 Setup: The same thing as for the first part, but for whatever is in the second part.

Context()->texStrings;
DISPLAY_SECTION( { name=>"2: Do something else", 
             canshow =>$scaffold->requireCorrect(1). " or $isInstructor",
             iscorrect=>$scaffold->requireCorrect(2,3), 
             section=>2
},   <<'END_SECTION'); 
Now again we have the problem text for the second part 
of the problem. We can have multiple answers for each part. 
$BR
To move on, type "1" for the first answer, and 
select "Correct" for the pull-down menu. 
$PAR
First Answer of Part 2: \{ans_rule(15) \}
$BR
Second Answer of Part 2: \{ $popup->menu() \}

END_SECTION

Part 2 Main Text: Again, we have another setup. This includes normal setup for the content of the part of the compound problem. We also have

DISPLAY_SECTION( { name=>"2: Do something else", 
             canshow =>$scaffold->requireCorrect(1). " or $isInstructor",
             iscorrect=>$scaffold->requireCorrect(2,3), 
             section=>2
},   <<'END_SECTION'); 

name=>"2: Do something else", again sets this as the label for the part of the problem. canshow =>$scaffold->requireCorrect(1). " or $isInstructor", designates that in order to show this part, one must have the first answer of the problem correct, or have $isInstructor true. iscorrect=>$scaffold->requireCorrect(2,3), makes it so that in order for this part of the question to be considered correct, on must have the second and third answer of the question correct. It should be noted that this is a continuing list of answers for the entire problem, not just for the section. The first part has one answer, but the second part has two, so we only set the second and third to count for the second part of the problem. Again, section=>2 tells us that this is the second part of the question.

Context()->normalStrings;
ANS($ans->cmp,
         $popup->cmp);

SECTION_SOLUTION({section=>2},<<'END_SOLUTION');
Here's a different solution.
END_SOLUTION

Part 2 Answer evaluation and Solutions: This is another solution one may have. Its syntax is identical to the first solution.

Context()->normalStrings;

##############
#  Section 3
##############
Context("Point");
Context()->strings->add("yes"=>{});
$ans = Point(1,6);

Part 3 Setup: Again, we have setup as we would as if the this part of the question were separate. We can, however, have problem-wide variables and functions.

Context()->texStrings;
DISPLAY_SECTION(
{	name=>"3: It's time for step 3!", 
    canshow =>$scaffold->requireCorrect(2,3). " or $isInstructor",
    iscorrect=>$scaffold->requireCorrect(4), 
    section=>3
},   <<'END_SECTION'); 

Finally, the fourth answer is: 
\{SECTION_ANS(Compute("yes")->cmp), Compute("yes")->ans_rule(15) \}
$BR
Look in the solution for the answer.
END_SECTION

Part 3 Main Text: This follows the same method as the second part's Main Text. We set name=>"3: It's time for step 3!", to be the name, canshow =>$scaffold->requireCorrect(2,3). " or $isInstructor", to indicate whether or not this part should be shown, iscorrect=>$scaffold->requireCorrect(4), to make it so this part of the question is considered correct if the fourth answer is marked right, and section=>3 tells us this is the third part of the question.

SECTION_SOLUTION({section=>3},<<'END_SOLUTION');
The solution is: Enter "yes".
END_SOLUTION

Part 3 Answer evaluation and Solutions: Essentially the same code as in part 1: we had the answers checked along with the answer blank.


PROCESS_ANSWERS();

$last_correct_section = PROCESS_SECTIONS();

$opensection = $last_correct_section + 1;
$scaffold->openSections($opensection);

TEXT($END_ONE_COLUMN);
ENDDOCUMENT();        

Finish: Here we use some boiler plate actions to make sure the answers are processed and that the correct section is opened. These process the question in its entirety and open the correct sections for the whichever part of the problem the user is on.


Problem Techniques Index


follow us