Advertisement
Layth01

Untitled

Mar 30th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 12.73 KB | None | 0 0
  1. unit MitosisQuestionsUnit;
  2.  
  3. interface
  4.  
  5. uses
  6.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  7.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
  8.   Vcl.Imaging.GIFImg;
  9.  
  10. type
  11.   TfrmMitosisQuestions = class(TForm)
  12.     rgrpQuestion1: TRadioGroup;
  13.     rgrpQuestion2: TRadioGroup;
  14.     rgrpQuestion3: TRadioGroup;
  15.     rgrpQuestion4: TRadioGroup;
  16.     imgMetaphase: TImage;
  17.     btnSubmit: TButton;
  18.     procedure btnSubmitClick(Sender: TObject);
  19.   private
  20.     { Private declarations }
  21.   public
  22.     { Public declarations }
  23.   end;
  24.  
  25. var
  26.   frmMitosisQuestions: TfrmMitosisQuestions;
  27.  
  28. implementation
  29.  
  30. {$R *.dfm}
  31.  
  32. Uses
  33.   LoginUnit;
  34.  
  35. procedure TfrmMitosisQuestions.btnSubmitClick(Sender: TObject);
  36. Var
  37. CorrectAnswers : Integer;
  38. FinalScore : String;
  39. ResultsFile : Textfile;
  40. Today : TDateTime;
  41. begin
  42.   CorrectAnswers := 0;
  43.   if rgrpQuestion1.ItemIndex = 1 then   //if answer is correct for question 1
  44.     CorrectAnswers := CorrectAnswers + 1;
  45.   if rgrpQuestion2.ItemIndex = 0 then   //if answer is correct for question 2
  46.     CorrectAnswers := CorrectAnswers + 1;
  47.   if rgrpQuestion3.ItemIndex = 3 then   //if answer is correct for question 3
  48.     CorrectAnswers := CorrectAnswers + 1;
  49.   if rgrpQuestion4.ItemIndex = 1 then   //if answer is correct for question 4
  50.     CorrectAnswers := CorrectAnswers + 1;
  51.  
  52.   //Display total mark to user
  53.   FinalScore := ('You scored: ' + IntToStr(CorrectAnswers) + ' out of 4');
  54.   ShowMessage(FinalScore);
  55.  
  56.    //CorrectAnswers needed to be converted to str - Show in developmental testing
  57.    //done
  58.  
  59.  
  60.   {if CorrectAnswers = 4 then
  61.     ShowMessage('Well Done you got full marks');
  62.   if CorrectAnswers = 0 then
  63.     ShowMessage('You need more revision');}
  64.   //put the above in prototype 2 - for 'usability features'
  65.  
  66.  
  67.   Today := Now; //assigns the current date and time to the variable 'Today'
  68.  
  69.   //Writing results to file accessed by teacher:
  70.   AssignFile(ResultsFile , 'StudentScores.txt');
  71.   Append(ResultsFile);
  72.   writeln(ResultsFile , '');
  73.   writeln(ResultsFile , ('Mitosis Multiple Choice Questions: ' //write name of test
  74.                           + IntToStr(CorrectAnswers) + '/4')); //write mark
  75.   writeln(ResultsFile , frmLogin.ledtUsername.Text); //write username to file
  76.   writeln(ResultsFile , ('On: ' + DateToStr(Today) + '    At: ' + TimeToStr(Today)));
  77.  
  78.   CloseFile(ResultsFile);
  79.  
  80.  
  81. end;
  82.  
  83. end.
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99. unit MitosisQuestionsUnit;
  100.  
  101. interface
  102.  
  103. uses
  104.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  105.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
  106.   Vcl.Imaging.GIFImg;
  107.  
  108. type
  109.   TfrmMitosisQuestions = class(TForm)
  110.     rgrpQuestion1: TRadioGroup;
  111.     rgrpQuestion2: TRadioGroup;
  112.     rgrpQuestion3: TRadioGroup;
  113.     rgrpQuestion4: TRadioGroup;
  114.     imgQuestion4: TImage;
  115.     btnSubmit: TButton;
  116.     btnExit: TButton;
  117.     lblAnswer1: TLabel;
  118.     lblAnswer2: TLabel;
  119.     lblAnswer3: TLabel;
  120.     lblAnswer4: TLabel;
  121.     procedure btnSubmitClick(Sender: TObject);
  122.     procedure btnExitClick(Sender: TObject);
  123.     procedure FormCreate(Sender: TObject);
  124.   private
  125.     { Private declarations }
  126.   public
  127.     { Public declarations }
  128.   end;
  129.  
  130. var
  131.   frmMitosisQuestions: TfrmMitosisQuestions;
  132.  
  133. implementation
  134.  
  135. {$R *.dfm}
  136.  
  137. Uses
  138.   LoginUnit , ASTopicSelectionUnit;
  139.  
  140. procedure TfrmMitosisQuestions.btnSubmitClick(Sender: TObject);
  141. Var
  142. CorrectAns : Integer;
  143. FinalScore : String;
  144. ResultsFile : Textfile;
  145. Today : TDateTime;
  146. begin
  147.  
  148.   btnSubmit.Enabled := False;   //disables submit button
  149.  
  150.   CorrectAns := 0;
  151.  
  152.   if rgrpQuestion1.ItemIndex = 1 then   //if answer is correct for question 1
  153.     CorrectAns := CorrectAns + 1
  154.   Else
  155.     lblAnswer1.Visible := True;          //show correct answer for question 1
  156.  
  157.   if rgrpQuestion2.ItemIndex = 0 then   //if answer is correct for question 2
  158.     CorrectAns := CorrectAns + 1
  159.   Else
  160.     lblAnswer2.Visible := True;          //show correct answer for question 2
  161.  
  162.   if rgrpQuestion3.ItemIndex = 3 then   //if answer is correct for question 3
  163.     CorrectAns := CorrectAns + 1
  164.   Else                                  //show correct answer for question 3
  165.     lblAnswer3.Visible := True;
  166.  
  167.   if rgrpQuestion4.ItemIndex = 1 then   //if answer is correct for question 4
  168.     CorrectAns := CorrectAns + 1
  169.   Else
  170.     lblAnswer4.Visible := True;          //show correct answer for question 4
  171.  
  172.   //Display total mark to user
  173.   FinalScore := ('You scored: ' + IntToStr(CorrectAns) + ' out of 4');
  174.   ShowMessage(FinalScore);
  175.  
  176.  
  177.   {if CorrectAnswers = 4 then
  178.     ShowMessage('Well Done you got full marks');
  179.   if CorrectAnswers = 0 then
  180.     ShowMessage('You need more revision');}
  181.   //put the above in prototype 3 - for 'usability features'
  182.  
  183.  
  184.   Today := Now; //assigns the current date and time to the variable 'Today'
  185.  
  186.   //Writing results to student's report file:
  187.   AssignFile(ResultsFile , frmLogin.ledtUsername.Text + '.txt');
  188.   Append(ResultsFile);
  189.   writeln(ResultsFile , '');
  190.   writeln(ResultsFile , ('Mitosis Multiple Choice Questions: ' //write name of test
  191.                           + IntToStr(CorrectAns) + '/4')); //write mark
  192.   writeln(ResultsFile , ('On: ' + DateToStr(Today) + '    At: ' + TimeToStr(Today)));
  193.  
  194.   CloseFile(ResultsFile);
  195. end;
  196.  
  197.  
  198. procedure TfrmMitosisQuestions.FormCreate(Sender: TObject);
  199. begin
  200.   //disables close button (top-right corner):
  201.   EnableMenuItem( GetSystemMenu( handle, False ),SC_CLOSE, MF_BYCOMMAND or MF_GRAYED );
  202. end;
  203.  
  204. //Close the form - goes back to AS Topic Selection:
  205. procedure TfrmMitosisQuestions.btnExitClick(Sender: TObject);
  206. begin
  207.   frmMitosisQuestions.Close;
  208.   frmASTopicSelect.Show;
  209. end;
  210.  
  211.  
  212.  
  213. end.
  214.  
  215.  
  216.  
  217.  
  218.  
  219.  
  220.  
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230. unit MitosisQuestions1Unit;
  231.  
  232. interface
  233.  
  234. uses
  235.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  236.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls,
  237.   Vcl.Imaging.GIFImg;
  238.  
  239. type
  240.   TfrmMitosisQuestions = class(TForm)
  241.     rgrpQuestion1: TRadioGroup;
  242.     rgrpQuestion2: TRadioGroup;
  243.     rgrpQuestion3: TRadioGroup;
  244.     rgrpQuestion4: TRadioGroup;
  245.     imgQuestion4: TImage;
  246.     btnExit: TButton;
  247.     lblAnswer1: TLabel;
  248.     lblAnswer2: TLabel;
  249.     lblAnswer3: TLabel;
  250.     lblAnswer4: TLabel;
  251.     lblTitle: TLabel;
  252.     rgrpQuestion5: TRadioGroup;
  253.     lblAnswer5: TLabel;
  254.     btnNextPage: TButton;
  255.     procedure btnExitClick(Sender: TObject);
  256.     procedure btnNextPageClick(Sender: TObject);
  257.   private
  258.     { Private declarations }
  259.   public
  260.     { Public declarations }
  261.   end;
  262.  
  263. var
  264.   frmMitosisQuestions: TfrmMitosisQuestions;
  265.  
  266. implementation
  267.  
  268. {$R *.dfm}
  269.  
  270. Uses
  271.   LoginUnit , ASTopicSelectionUnit , MitosisQuestions2Unit;
  272.  
  273. //show the next page of questions
  274. procedure TfrmMitosisQuestions.btnNextPageClick(Sender: TObject);
  275. begin
  276.   frmMitosisQuestionsII.Show;
  277. end;
  278.  
  279. //Close both question forms - goes back to AS Topic Selection:
  280. procedure TfrmMitosisQuestions.btnExitClick(Sender: TObject);
  281. begin
  282.   frmMitosisQuestions.Close;
  283.   frmMitosisQuestionsII.Close;
  284.   frmASTopicSelect.Show;
  285. end;
  286.  
  287.  
  288.  
  289. end.
  290.  
  291.  
  292.  
  293.  
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302. unit MitosisQuestions2Unit;
  303.  
  304. interface
  305.  
  306. uses
  307.   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  308.   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls;
  309.  
  310. type
  311.   TfrmMitosisQuestionsII = class(TForm)
  312.     rgrpQuestion6: TRadioGroup;
  313.     rgrpQuestion7: TRadioGroup;
  314.     rgrpQuestion8: TRadioGroup;
  315.     rgrpQuestion9: TRadioGroup;
  316.     rgrpQuestion10: TRadioGroup;
  317.     lblAnswer6: TLabel;
  318.     lblAnswer7: TLabel;
  319.     lblAnswer8: TLabel;
  320.     lblAnswer9: TLabel;
  321.     lblAnswer10: TLabel;
  322.     btnSubmit: TButton;
  323.     btnExit: TButton;
  324.     procedure btnSubmitClick(Sender: TObject);
  325.     procedure btnExitClick(Sender: TObject);
  326.   private
  327.     { Private declarations }
  328.   public
  329.     { Public declarations }
  330.   end;
  331.  
  332. var
  333.   frmMitosisQuestionsII: TfrmMitosisQuestionsII;
  334.  
  335. implementation
  336.  
  337. {$R *.dfm}
  338.  
  339. Uses
  340.   MitosisQuestions1Unit , LoginUnit , ASTopicSelectionUnit;
  341.  
  342. //Close both question forms - goes back to AS Topic Selection:
  343. procedure TfrmMitosisQuestionsII.btnExitClick(Sender: TObject);
  344. begin
  345.   frmMitosisQuestions.Close;
  346.   frmMitosisQuestionsII.Close;
  347.   frmASTopicSelect.Show;
  348. end;
  349.  
  350. procedure TfrmMitosisQuestionsII.btnSubmitClick(Sender: TObject);
  351. Var
  352.   FinalScore : String;
  353.   Today : TDateTime;
  354.   ResultsFile : TextFile;
  355.   CorrectAns : Integer;
  356.   PresenceCheck : Bool;
  357. begin
  358.    presencecheck := True;
  359.  
  360.   //presence check for each question:
  361.   if frmMitosisQuestions.rgrpQuestion1.ItemIndex = -1 then
  362.     presencecheck := False
  363.   Else if frmMitosisQuestions.rgrpQuestion2.ItemIndex = -1 then
  364.     presencecheck := False
  365.   Else if frmMitosisQuestions.rgrpQuestion3.ItemIndex = -1 then
  366.     presencecheck := False
  367.   Else if frmMitosisQuestions.rgrpQuestion4.ItemIndex = -1 then
  368.     presencecheck := False
  369.   Else if frmMitosisQuestions.rgrpQuestion5.ItemIndex = -1 then
  370.     presencecheck := False
  371.   Else if rgrpQuestion6.ItemIndex = -1 then
  372.     presencecheck := False
  373.   Else if rgrpQuestion7.ItemIndex = -1 then
  374.     presencecheck := False
  375.   Else if rgrpQuestion8.ItemIndex = -1 then
  376.     presencecheck := False
  377.   Else if rgrpQuestion9.ItemIndex = -1 then
  378.     presencecheck := False
  379.   Else if rgrpQuestion10.ItemIndex = -1 then
  380.     presencecheck := False;
  381.  
  382.   if presencecheck = False  then
  383.     ShowMessage('You have not completed all the questions')
  384.  
  385.  
  386.   Else
  387.   Begin
  388.     CorrectAns := 0;
  389.  
  390.     if frmMitosisQuestions.rgrpQuestion1.ItemIndex = 1 then //if answer is correct for question 1
  391.       CorrectAns := CorrectAns + 1
  392.     Else
  393.       frmMitosisQuestions.lblAnswer1.Visible := True;    //show correct answer for question 1
  394.  
  395.     if frmMitosisQuestions.rgrpQuestion2.ItemIndex = 0 then   //if answer is correct for question 2
  396.       CorrectAns := CorrectAns + 1
  397.     Else
  398.       frmMitosisQuestions.lblAnswer2.Visible := True;   //show correct answer for question 2
  399.  
  400.     if frmMitosisQuestions.rgrpQuestion3.ItemIndex = 3 then   //if answer is correct for question 3
  401.       CorrectAns := CorrectAns + 1
  402.     Else
  403.       frmMitosisQuestions.lblAnswer3.Visible := True;  //show correct answer for question 3
  404.  
  405.     if frmMitosisQuestions.rgrpQuestion4.ItemIndex = 1 then  //if answer is correct for question 4
  406.       CorrectAns := CorrectAns + 1
  407.     Else
  408.       frmMitosisQuestions.lblAnswer4.Visible := True;   //show correct answer for question 4
  409.  
  410.     if frmMitosisQuestions.rgrpQuestion5.ItemIndex = 2 then //if answer is correct for question 5
  411.       CorrectAns := CorrectAns + 1
  412.     Else
  413.       frmMitosisQuestions.lblAnswer5.Visible := True; //show correct answer for question 5
  414.  
  415.     if rgrpQuestion6.ItemIndex = 0 then //if answer is correct for question 6
  416.       CorrectAns := CorrectAns + 1
  417.     Else
  418.       lblAnswer6.visible := True;    //show correct answer for question 6
  419.  
  420.     if rgrpQuestion7.ItemIndex = 3 then //if answer is correct for question 7
  421.       CorrectAns := CorrectAns + 1
  422.     Else
  423.       lblAnswer7.visible := True;   //show correct answer for question 7
  424.  
  425.     if rgrpQuestion8.ItemIndex = 1 then //if answer is correct for question 8
  426.       CorrectAns := CorrectAns + 1
  427.     Else
  428.       lblAnswer8.visible := True;   //show correct answer for question 8
  429.  
  430.     if rgrpQuestion9.ItemIndex = 0 then //if answer is correct for question 9
  431.       CorrectAns := CorrectAns + 1
  432.     Else
  433.       lblAnswer9.visible := True;   //show correct answer for question 9
  434.  
  435.     if rgrpQuestion10.ItemIndex = 1 then //if answer is correct for question 10
  436.       CorrectAns := CorrectAns + 1
  437.     Else
  438.       lblAnswer10.visible := True;  //show correct answer for question 10
  439.  
  440.  
  441.  
  442.     btnSubmit.Enabled := False;   //disables submit button
  443.  
  444.  
  445.  
  446.     //Display total mark to user
  447.     FinalScore := ('You scored: ' + IntToStr(CorrectAns) + ' out of 10');
  448.     ShowMessage(FinalScore);
  449.  
  450.     //display feedback based on results:
  451.     if CorrectAns = 10 then
  452.       ShowMessage ('Well Done! You got full marks.');
  453.     if CorrectAns < 5 then
  454.       ShowMessage('You need more revision on this topic.');
  455.     if CorrectAns > 6 then
  456.       ShowMessage('You''re on track for this topic - but there are still areas to improve!');
  457.  
  458.  
  459.  
  460.     Today := Now; //assigns the current date and time to the variable 'Today'
  461.  
  462.     //Writing results to student's report file:
  463.     AssignFile(ResultsFile , frmLogin.ledtUsername.Text + '.txt');
  464.     Append(ResultsFile);
  465.     writeln(ResultsFile , '');
  466.     writeln(ResultsFile , ('Mitosis Multiple Choice Questions: ' //write name of test
  467.                           + IntToStr(CorrectAns) + '/10')); //write mark
  468.     writeln(ResultsFile , ('On: ' + DateToStr(Today) + '    At: ' + TimeToStr(Today)));
  469.     CloseFile(ResultsFile);
  470.   End;
  471. end;
  472.  
  473. end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement