home *** CD-ROM | disk | FTP | other *** search
- PROCEDURE Init_Question;
-
- VAR
- {problem oriented variables follow}
- {integer variables}
- I_num_1,I_num_2 : Integer;
-
- {real variables}
- R_1, { price of first item}
- R_2, { price of second item }
- R_3: REAL; { total amount of money available }
- final_item_one,
- final_item_two,
- final_total_dollars,
- final_total_amount : REAL;
-
- {string variables}
- A_R_1,A_R_2,A_R_3: STRING; { STRING equivalents of above for printing }
- A_final_item_one,
- A_final_item_two,
- A_final_total_dollars,
- A_final_total_amount : STRING;
-
- CONST
- A_1 : ARRAY [1..3] OF STRING = ('Peanuts','Almonds','Walnuts');
- A_2 : ARRAY [1..3] OF STRING = ('Cashews','Macadamia','Brazil nuts');
-
- BEGIN
- {$I-}
- Assign(OldQuestionFile,Progname_String+'.SAV');
- Reset(OldQuestionFile);
- {$I+}
- IF IOResult = 0
- THEN {there was a save file}
- BEGIN
- ReadLn(OldQuestionFile,
- I_num_1);
- ReadLn(OldQuestionFile,I_num_2);
- ReadLn(OldQuestionFile,R_1);
- ReadLn(OldQuestionFile,R_2);
- ReadLn(OldQuestionFile,final_item_one);
- ReadLn(OldQuestionFile,final_item_two);
- Close(OldQuestionFile);
- END
- ELSE {there was no save file, create one}
- BEGIN
- { question creation section
- in this section we create the variables which will change between
- students.}
-
- I_num_1 := random(3)+1;
- I_num_2 := random(3)+1;
- R_1 := 10*(Random); { price of first item }
- R_2 := 10.*Random + R_1; { price of second item }
-
- final_item_one := 3.* Random;
- final_item_two := 3.* Random;
-
-
- ReWrite(OldQuestionFile); {create the .SAV file if none existed,
- so if student returns to this
- question, the same variables will
- appear }
- Writeln(OldQuestionFile,
- I_num_1);
- Writeln(OldQuestionFile,I_num_2);
- Writeln(OldQuestionFile,R_1);
- Writeln(OldQuestionFile,R_2);
- Writeln(OldQuestionFile,final_item_one);
- Writeln(OldQuestionFile,final_item_two);
- Close(OldQuestionFile);
- END;
-
- {the following variables are dependent on the student's variables}
- Str(R_1:3:2,A_R_1);
- Str(R_2:3:2,A_R_2);
- final_total_dollars := final_item_one*R_1 + final_item_two*R_2;
- final_total_amount := final_item_one + final_item_two;
- Str(final_item_one:5:2,A_final_item_one);
- Str(final_item_two:5:2,A_final_item_two);
- Str(final_total_dollars:5:2,A_final_total_dollars);
- Str(final_total_amount:5:2,A_final_total_amount);
- true_answer := final_item_two;
-
- question := A_1[I_num_1]+' cost $'+A_R_1+' per pound.';
- question := question + ' '+A_2[I_num_2]+' cost $'+A_R_2+' per pound.';
- question := question + ' If a person wished to purchase '+
- A_final_total_amount+ ' pounds of nuts and wishes ';
- question := question + ' to spend $'+A_final_total_dollars+' for nuts, how many ' ;
- question := question + 'pounds of '+A_2[I_num_2]+' should that person purchase?' ;
- IF MaxAvail < Sizeof(Wrong_Answers) {repeat this for each error response}
- THEN
- BEGIN
- ClrScr;
- WriteLn('Not Enough Memory For Errors');
- Noise(Bad);
- END
- ELSE
- New(RootErrorPtr);
- TempPtr := RootErrorPtr;
- TempPtr^.value := final_total_amount;
- TempPtr^.remark := 'Did you calculate the total amount of nuts?';
- IF MaxAvail < Sizeof(Wrong_Answers)
- THEN
- BEGIN
- ClrScr;
- WriteLn('Not Enough Memory For Errors');
- Noise(Bad);
- END
- ELSE
- New(GenTempPtr);
- TempPtr^.Next := GenTempPtr;
- TempPtr := GenTempPtr;
- TempPtr^.value := (final_total_dollars - R_2*final_total_amount)/(R_1-R_2);
- TempPtr^.remark := 'Did you mix up '+A_1[I_num_1]+ ' and '+A_2[I_num_2]+'?';
- TempPtr^.Next := NIL;
-
- {$IFDEF Watch_Student}
- WriteLn(OutFile,Time_Stamp);
- WriteLn(OutFile,question);
- WriteLn(OutFile,'final_item_one[',A_1[I_num_1]+'] = ',final_item_one);
- WriteLn(OutFile,'final_item_two['+A_2[I_num_2]+'] = ',final_item_two);
- WriteLn(OutFile,'final_total_dollars = ', final_total_dollars);
- WriteLn(OutFile,'final_total_amount = ',final_total_amount);
- {$ENDIF}
- IF MaxAvail < Sizeof(Debug_Lines) {repeat this for each debug response}
- THEN
- BEGIN
- ClrScr;
- WriteLn('Not Enough Memory For Errors');
- Noise(Bad);
- END
- ELSE
- BEGIN
- New(TempDebugLinePtr);
- RootDebugLinePtr := TempDebugLinePtr;
- TempDebugLinePtr^.line := 'final_item_one['+A_1[I_num_1]+'] = '+A_final_item_one;
- TempDebugLinePtr^.next := NIL;
- END;
- IF MaxAvail < Sizeof(Debug_Lines)
- THEN
- BEGIN
- ClrScr;
- WriteLn('Not Enough Memory For Errors');
- Noise(Bad);
- END
- ELSE BEGIN
- New(GenTempDebugPtr);
-
- TempDebugLinePtr^.next := GenTempDebugPtr;
- TempDebugLinePtr := GenTempDebugPtr;
- TempDebugLinePtr^.line := 'final_item_two['+A_2[I_num_2]+'] = '+
- A_final_item_two;
- TempDebugLinePtr^.next := NIL;
- END;
- Choice_Line :=
- 'How many pounds of '+A_2[I_num_2]+' should this person buy?';
-
- END;
-