2013-05-07 81 views
0

我想用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. 
+4

这个问题太广泛了。请尝试一下,如果遇到问题,您可以随时提出具体问题。如果您以前从未编写过任何严重的Delphi程序,请考虑阅读本书或教程。 – 2013-05-07 18:54:51

+1

@anakata:因为这是StackOverflow上的第20547个Delphi问题,所以你必须在这里是新的。 – 2013-05-07 19:00:38

+0

@ToonKrijthe我明白,但你知道我在哪里可以得到相同程序的源代码 – user2353538 2013-05-07 19:24:25

回答

0

为了部分回答:
如果你想保持用户的分数就这个级别的进展最好的办法就是让第二个文本文件,用于维护用户名和得分。
将它们读入数组中。在程序启动时询问用户名,运行测验,看看你是否已经认识他,更新数组,然后写回来。

您的下一步将学习数据库访问并将所有数据存储在数据库中而不是文本文件中。

这应该给你足够的锻炼,现在;-)

像香椿说,请在这里提出的具体问题:我想这一点,尝试这种(这里的代码),此操作失败,该如何解决?

另外,一旦你有一个工作程序,你可能想要把它放在https://codereview.stackexchange.com/要求改进。
StackOverflow不是那个地方。