CompoundProblem5

From WeBWorK_wiki
Revision as of 12:35, 28 February 2016 by Scorwin (talk | contribs) (Fixed code in Section 3 to make the problem work.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.

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

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

SECTION_ANS($ans->cmp, $popup->cmp);

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(1,2). " or $isInstructor",
    iscorrect=>$scaffold->requireCorrect(3), 
    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