我正在尝试制作一个包含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.发布于 2013-05-08 04:02:24
以下是部分答案:
如果您希望维护用户分数,那么在此级别上取得进展的最好方法是创建第二个文本文件来维护用户名和分数。
将它们读入数组。在程序启动时询问用户名,运行测验,看看您是否认识他,更新数组,然后将其写回。
您的下一步将是学习数据库访问并将所有数据存储在数据库中,而不是文本文件中。
这应该会给你足够的锻炼;-)
就像Toon说的,请在这里提出具体的问题:我想要这个,尝试这个(这里是代码),这个失败了,如何解决?
此外,一旦你有了一个可以工作的程序,你可能会想要把它放到https://codereview.stackexchange.com/上来请求改进。
StackOverflow不是适合这样做的地方。
https://stackoverflow.com/questions/16426111
复制相似问题