2013-05-07 83 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不是那個地方。