我正在尝试制作一个包含 30 个问题(15 个多项选择)的简单测验程序,并将所有问题的顺序随机化。它还必须将结果计算为百分比,并以正确答案显示错误回答的问题。即使只是一个包含 3 或 4 个示例问题的样本也可以。
我不希望同一个问题出现不止一次。有没有我可以下载的免费源代码,以便我学习如何很好地做到这一点。我只是一个新手,我真的很想学习并看看使用的策略。
我设法做到了,它正在从文本文件中读取问题,但我想修改它以显示用户名和以前用户的分数,我希望能对我的程序进行修改,或者如果有人有源代码简单的测验程序,我将不胜感激。
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,Unit2, StdCtrls, Grids;
type
TForm1 = class(TForm)
Button1: TButton;
StringGrid1: TStringGrid;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
var
namefile, tmp : string;
f: text;
l,i,j,c: integer;
cc: double;
mas: array [1..100] of integer;
procedure TForm1.Button1Click(Sender: TObject);
begin
reset(f);
readln(f,l);
for I := 1 to l do
begin
Form2.Label1.Caption := 'Вопрос № '+Inttostr(i+1);
readln(f,tmp);
Form2.Label2.Caption := tmp;
readln(f,tmp);
Form2.RadioButton1.Caption := tmp;
readln(f,tmp);
Form2.RadioButton2.Caption :=tmp;
readln(f,tmp);
Form2.RadioButton3.Caption :=tmp;
readln(f,tmp);
Form2.RadioButton4.Caption :=tmp;
readln(f,j);
Form2.ShowModal;
if (Form2.RadioButton1.Checked) then
if (j=1) then
mas[i]:=1;
if (Form2.RadioButton2.Checked) then
if (j=2) then
mas[i]:=1;
if (Form2.RadioButton3.Checked) then
if (j=3) then
mas[i]:=1;
if (Form2.RadioButton4.Checked) then
if (j=4) then
mas[i]:=1;
end;
c:=0;
for I := 1 to l do
if mas[i]=1 then
c:=c+1;
cc:=(c*100)/l;
label3.Caption:= 'Правильных ответов '+FloatToStr(cc)+'%';
for I := 0 to l-1 do
stringgrid1.Cells[i,1]:=IntToStr(mas[i+1]);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
namefile:='test.txt';
AssignFile(f, namefile);
reset(f);
readln(f,l);
stringgrid1.ColCount:=l;
for I := 1 to l do
mas[i]:=0;
for I := 0 to l-1 do
stringgrid1.Cells[i,0]:=IntToStr(i+1);
for I := 0 to l-1 do
stringgrid1.Cells[i,1]:=IntToStr(mas[i+1]);
end;
end.