📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, jpeg, ComCtrls,DateUtils;
type
TForm1 = class(TForm)
Image1: TImage;
Label1: TLabel;
Label2: TLabel;
Button1: TButton;
Button2: TButton;
Label3: TLabel;
Bevel1: TBevel;
Label4: TLabel;
Edit1: TEdit;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Label8: TLabel;
Bevel2: TBevel;
Memo1: TMemo;
ComboBox1: TComboBox;
Label9: TLabel;
Image2: TImage;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Edit1KeyPress(Sender: TObject; var Key: Char);
procedure Edit1Change(Sender: TObject);
procedure Edit1Key1Up(Sender: TObject; var Key: Word;
Shift: TShiftState);
private
{ Private declarations }
QCount:integer;//问题数量
QIndex:integer;//问题位置
QList:TstringList;//问题列表
AList:TstringList;//答案列表
FList:TstringList;//作答列表
startTime:TDatetime;//开始时间
EndTime:TDateTime; //结束时间
Count_OK:integer;
Count_Fail:integer;
MaxNum:integer; //最大数值
procedure init;
procedure Builder(aList,bList:TstringList;aCount:integer);
procedure ShowQ(aIndex: integer);
procedure ShowTime(eTime:Tdatetime);
procedure Showanswers;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses unit2, Unit3,Unit4;
{$R *.dfm}
Function BookLeftSpace(s:string;len:integer):string;
begin
if length(s)>len then setlength(s,len)
else while length(s)<Len do s:=' '+s;
result:=s;
end;
Function BookRightSpace(s:string;len:integer):string;
begin
if length(s)>len then setlength(s,len)
else while length(s)<Len do s:=s+' ';
result:=s;
end;
Function StringToint(s:string;def:integer=0):integer;
begin
result:=def;
s:=trim(s);
if s='' then exit;
try
result:=strtoint(s);
Except
result:=def;
end;
end;
Function showstr(str:string;F:boolean=False;Titlestr:string='注意'):boolean;
begin
result:=False;
if not F then
begin
application.MessageBox(pchar(str),pchar(titlestr),MB_OK);
exit;
end;
result:=application.MessageBox(pchar(str),pchar(titlestr),MB_OKCancel)=IDOK;
end;
procedure TForm1.init;
begin
Memo1.Left:=200;
Memo1.Top:=32;
memo1.Height:=81;
memo1.Width:=345;
Memo1.Visible:=true;
Label9.Visible:=true;
combobox1.Visible:=true;
Label3.Visible:=false;
Label6.Visible:=false;
Label7.Visible:=false;
Label8.Visible:=false;
Label4.Caption:='你希望出多少题?';
Edit1.Text:='20';
Combobox1.ItemIndex:=0;
MaxNum:=0;
QIndex:=-1;
QCount:=0;
Count_OK:=0;
Count_Fail:=0;
Button1.Caption:='开始';
Button2.Caption:='离开';
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
Randomize;
QCount:=0;//问题数量
QIndex:=-1;//问题位置
QList:=TstringList.Create;//问题列表
AList:=TstringList.Create;//答案列表
FList:=TstringList.Create;//作答列表
startTime:=now;//开始时间
EndTime:=now; //结束时间
MaxNum:=0;
init;
end;
procedure TForm1.Builder(aList,bList:TstringList;aCount:integer);
const p:array[0..1] of string=('-','+');
var i,j,k,res:integer;
m,n:integer;
a,b,c,d:integer;
s1,s2:string;
begin
aList.Clear;
bList.Clear;
FList.Clear;
for i:=0 to aCount-1 do
begin
d:=-1;
while d<0 do
begin
m:=random(100);
n:=random(100);
m:=ord(odd(m));
n:=ord(odd(n));
a:=random(MaxNum);
b:=random(MaxNum);
if m=1 then
j:=a+b
else
j:=a-b;
if (j<0) or (j>MaxNum) then continue;
if n=1 then
k:=MaxNum-j
else
K:=j;
c:=random(k);
if n=1 then
res:=j+C
else
res:=j-c;
if (res<0) or (res>MaxNum) then continue;
s1:= inttostr(a)+p[m]+inttostr(b)+p[n]+inttostr(c)+' = ';
if (aList.IndexOf(s1)>=0) then continue;
d:=res;
end;
s2:=inttostr(d);
aList.Add(s1) ;
bList.Add(s2) ;
end;
end;
procedure TForm1.ShowQ(aIndex:integer);
begin
label5.Caption:='第'+inttostr(QIndex+1)+'题 共'+inttostr(QCount)+'题 成绩: 对'+inttostr(Count_OK)+'题错'+inttostr(Count_Fail)+'题';
if aIndex>=QList.Count then exit;
Label4.Caption:=QList[aIndex];
Edit1.Text:='';
end;
procedure TForm1.ShowTime(eTime:Tdatetime);
var nowT:int64;
begin
//计算对错 时间
Label3.Visible:=true;
Label6.Visible:=true;
Label7.Visible:=true;
Label8.Visible:=true;
nowT:=SecondsBetween(now,starttime);
if (nowT div (QIndex+1))=0 then
Label6.Caption:=inttostr(MilliSecondsBetween(now,starttime) div (QIndex+1))+'豪秒'
else
if (nowT > ((QIndex+1)*90) ) then
Label6.Caption:=inttostr(MinutesBetween(now,starttime) div (QIndex+1))+'分'
else
Label6.Caption:=inttostr(nowT div (QIndex+1))+'秒';
if (nowT<1) then
Label8.Caption:=inttostr(MilliSecondsBetween(now,starttime))+'豪秒'
else
if (nowT > 90) then
Label8.Caption:=inttostr(nowT div 60)+'分'+inttostr(nowT mod 60)+'秒'
else
Label8.Caption:=inttostr(nowT)+'秒';
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if Button1.caption='开始' then
begin
edit1.SetFocus;
QCount:=StringToint(Edit1.Text,-1);
if QCount<0 then
begin
showmessage('你填写的出题数量不正确,请重新再填写(1-100题)');
exit;
end;
if MaxNum=0 then
begin
case Combobox1.ItemIndex of
0 : MaxNum:=10;
1 : MaxNum:=20;
2 : MaxNum:=30;
3 : MaxNum:=50;
4 : MaxNum:=100;
end;
Builder(QList,AList,QCount);//创建题目
end;
QIndex:=0;
ShowQ(QIndex);
StartTime:=now;
memo1.Visible:=false;
Label9.Visible:=false;
combobox1.Visible:=false;
button1.Caption:='下一题';
if QIndex=QCount-1 then
Button1.Caption:='交卷';
button2.Visible:=true;
exit;
end;
if (Button1.caption='下一题') then
begin
edit1.SetFocus;
//先看看是否没有作答
if trim(Edit1.Text)='' then
begin
showmessage('你还没有作答,请先作答');
exit;
end;
//看看是否已经做完
if QIndex<QCount-1 then
begin
FList.Add(trim(Edit1.Text));
if AList[QIndex]=trim(Edit1.Text) then
inc(Count_OK)
else
inc(Count_Fail);
end;
inc(QIndex);
ShowQ(QIndex);
ShowTime(now);
//做下一道题
if QIndex=QCount-1 then
Button1.Caption:='交卷';
exit;
end;
if ( Button1.caption='交卷') then
begin
if QIndex<QCount-1 then exit;
edit1.SetFocus;
FList.Add(trim(Edit1.Text));
if AList[QIndex]=trim(Edit1.Text) then
inc(Count_OK)
else
inc(Count_Fail);
label5.Caption:='第'+inttostr(QIndex+1)+'题 共'+inttostr(QCount)+'题 成绩: 对'+inttostr(Count_OK)+'题错'+inttostr(Count_Fail)+'题';
endTime:=now;
ShowTime(now);
IF (Count_OK/QCount)>0.90 then
Form3.ShowModal
else
Form4.ShowModal;
showanswers;
init;
Button1.Caption:='开始';
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if (QIndex>=0)and (QIndex<QCount) then
begin
if showstr('你还没有答完问卷,是否现在就要离开'#13+'如果离开请按[确定按钮],否则请按[取消]按钮',true) then
close
else exit;
end
else
begin
//if showstr('你要现在就要离开这里吗?'#13+'如果离开请按[确定按钮],否则请按[取消]按钮',true) then
close
//else exit;
end;
end;
Function AllIsDigit(s:string):boolean;
var pStr:pchar;
begin
result:=false;
pStr:=pchar(s);
while pStr^<>#0 do
begin
if (pStr^<'0') or (pStr^>'9') then Exit;
inc(pStr);
end;
result:=True;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
begin
//if not AllIsDigit(key) then key:=#0;
if not AllIsDigit(trim(Edit1.Text+key)) then Key:=#0;
end;
procedure TForm1.Edit1Change(Sender: TObject);
begin
Button1.Enabled:=Stringtoint(trim(Edit1.Text),-1)>-1;
if (Button1.Caption='开始') then
Button1.Enabled:=(Stringtoint(trim(Edit1.Text),-1)>0) and (Stringtoint(trim(Edit1.Text),-1)<=100)
end;
procedure TForm1.Edit1Key1Up(Sender: TObject; var Key: Word;
Shift: TShiftState);
begin
if not AllIsDigit(trim(Edit1.Text)) then Key:=0;
end;
Function AnswerResult(s1,s2:string):string;
begin
if trim(s1)=trim(s2) then
result:='对'
else
result:='错'
end;
procedure TForm1.Showanswers;
var s1,s2:string;
nowT,i,j:integer;
begin
nowT:=SecondsBetween(now,starttime);
if (nowT div (QIndex+1))=0 then
s1:=inttostr(MilliSecondsBetween(now,starttime) div (QIndex+1))+'豪秒'
else
if (nowT > ((QIndex+1)*90) ) then
s1:=inttostr(MinutesBetween(now,starttime) div (QIndex+1))+'分'
else
s1:=inttostr(nowT div (QIndex+1))+'秒';
if (nowT<1) then
s2:=inttostr(MilliSecondsBetween(now,starttime))+'豪秒'
else
if (nowT > 90) then
s2:=inttostr(nowT div 60)+'分'+inttostr(nowT mod 60)+'秒'
else
s2:=inttostr(nowT)+'秒';
with Form2.RichEdit1.Lines do
begin
clear;
add('**************************************************************************************');
add('****** 小学数学加减法测验卷 ********');
add('**************************************************************************************');
add('题目总数:'+BookRightSpace(inttostr(QCount),25)+'题目类型:'+combobox1.Text);
add('作答时间:'+formatdatetime('yyyy-mm-dd hh:nn:ss',starttime)+' 交卷时间:'+formatdatetime('yyyy-mm-dd hh:nn:ss',endTime));
add('作答结果:答对'+inttostr(Count_OK)+'题 ,答错'+inttostr(Count_Fail)+'题');
add('正确比率:'+inttostr(Count_OK*100 div QCount)+'%');
add('时间效率:平均每题耗时'+S1+' 全部作答耗时:'+s2);
add('试卷情况:');
add('');
add(' 作答内容 评论 正确答案 ');
add('--------------------------------------------------------------------------------------');
for i:=0 to QCount-1 do
begin
Add(BookLeftSpace(QList[i],15)+BookRightSpace(FList[i],15)+BookLeftSpace(AnswerResult(FList[i],AList[i]),6)+BookLeftSpace('',12)+'正确答案:'+BookLeftSpace(QList[i],12)+BookRightSpace(AList[i],10));
end;
end;
//Form2.WindowState:=wsMaximized;
//Form2.UpdateControlState;
Form2.ShowModal;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -