CompoundProblem5

From WeBWorK_wiki
Revision as of 15:49, 30 June 2014 by Idelbrid (talk | contribs) (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...")
(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 problems as in Compound Problems, except this uses the macro compoundProblem5.pl. This creates a clean, folding interface for the problem, showing labels for each step.

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
);
#################
#Boiler Plate
#################
$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: We need make no changes to the initialization section of the file. In this example we include parserPopUp.pl so that we can use that.

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

Part 1 Setup: In this part of the problem, we do whatever we would normally do in setup that is required for the first section of the compound problem. Here we set the context and define an answer.

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: The text for the question is broken down by section into the parts that we want the student to work sequentially.

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, $evenNum1 and $evenNum2, we would test for completeness of the first part of the problem with


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.

###############
#  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: 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.


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: We haven't included the answer checking yet, so it's done here. We also have another solution.

Context()->normalStrings;

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

Part 3 Setup: The same thing as for the first two parts, but for whatever is in the third part.

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: Here we have "canshow" require 2 and 3 be correct, because those were the answers blanks in the second part. We also mark this correct when the fourth answer is right.


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.


Problem Techniques Index