-
Notifications
You must be signed in to change notification settings - Fork 0
/
LOperatiTest.pas
277 lines (249 loc) · 7.03 KB
/
LOperatiTest.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
Unit LOperatiTest;
{-------------------------------------------------------------------}
INTERFACE
{-------------------------------------------------------------------}
Uses
Forms, SysUtils, FileUtil, Messages, LazUtf8, Dialogs, classes,
extctrls, graphics, LazFileUtils,
LStringsN;
Type
TSudent=record
Name:String;
Tested:Boolean;
Ball:Integer;
end;
Var
WorkDir, NameQF, NameSF :String;
NumStudents, NumQuestions,
CurrStudent, CurrWStudent, CurrBall : Integer;
IsInputQ, IsInputS:boolean;
TheStudents: Array of TSudent;
TheQuestions: Array of TSudent;
Function OpenQuestionsDialog:Boolean;
Procedure TheOpenQuestions;
Procedure OpenQuestions(FName:String);
Function OpenStudentsDialog:Boolean;
Procedure TheOpenStudentsList;
Procedure OpenStudentsList(FName:String);
Procedure TheWork;
Procedure ResultView;
Procedure ResultOut;
Procedure GetStudent (n:integer; var st:String; var currw: integer);
Procedure GetQuestion(n:integer; var qe:String);
{-------------------------------------------------------------------}
IMPLEMENTATION
{-------------------------------------------------------------------}
Uses Unit1 ;
// Var LogFile:TextFile;
Function OpenQuestionsDialog:Boolean;
Var SavDir, FiniN1:String;
TempB:Boolean;
begin
GetDir(0,SavDir);
WorkDir:=SavDir;
Form1.OpenDialog1Qstns.InitialDir:=SavDir;
TempB:=Form1.OpenDialog1Qstns.Execute;
If TempB then
begin //--------If TempB
FiniN1:=Form1.OpenDialog1Qstns.FileName;
NameQF:=ExtractFileName(FiniN1);
Form1.StatusBar1.Panels[0].Text:=NameQF;
OpenQuestions(FiniN1);
IsInputQ:=True;
end; //--------If TempB
OpenQuestionsDialog:=TempB;
end;
Function OpenStudentsDialog:Boolean;
Var SavDir, FiniN1:String;
TempB:Boolean;
begin
GetDir(0,SavDir);
WorkDir:=SavDir;
Form1.OpenDialog2Stdnts.InitialDir:=SavDir;
TempB:=Form1.OpenDialog2Stdnts.Execute;
If TempB then
begin //--------If TempB
FiniN1:=Form1.OpenDialog2Stdnts.FileName;
NameSF:=ExtractFileName(FiniN1);
Form1.StatusBar1.Panels[1].Text:=NameSF;
// Form1.Label2Stdnts.Caption:=NameSF;
OpenStudentsList(FiniN1);
IsInputS:=True;
end; //--------If TempB
OpenStudentsDialog:=TempB;
end;
Procedure TheOpenQuestions;
begin
OpenQuestionsDialog
end;
Procedure OpenQuestions(FName:String);
Var
i:integer;
FT:TextFile;
list : TStringList;
begin
list := TstringList.Create;
list.LoadFromFile(FName);
NumQuestions:=list.count;
list.free;
SetLength(TheQuestions,NumQuestions+1);
AssignFile(FT,FName);
Reset(FT);
For i:=1 to NumQuestions do
begin
Readln(FT, TheQuestions[i].Name);
TheQuestions[i].Tested:=False;
end;
CloseFile(FT);
end;
Procedure TheOpenStudentsList;
begin
OpenStudentsDialog;
CurrStudent:=0;
Randomize;
// AssignFile(LogFile,'C:\tem.txt');
// Rewrite(LogFile);
end;
Procedure OpenStudentsList(FName:String);
Var
i:integer;
FT:TextFile;
list : TStringList;
begin
// NumStudents:=NumLineInTextFnotSp(FName);
list := TstringList.Create;
list.LoadFromFile(FName);
NumStudents:=list.count;
list.free;
SetLength(TheStudents,NumStudents+1);
AssignFile(FT,FName);
Reset(FT);
For i:=1 to NumStudents do
begin
Readln(FT, TheStudents[i].Name);
TheStudents[i].Ball:=0;
TheStudents[i].Tested:=False;
end;
CloseFile(FT);
end;
Procedure TheWork;
Const
NMax=23;
Var St, Qu, Qu1, S: String;
RestOfStrung:String;
i:integer;
begin
If not IsInputQ then begin
MessageDlg ('Вопросы не введены',mtInformation,[mbOk], 0); Exit;
end;
If not IsInputS then begin
MessageDlg ('Список студентов не введен',mtInformation,[mbOk], 0); Exit;
end;
i:=1;
If CurrStudent<NumStudents
then
begin //--------------
Inc(CurrStudent);
CurrBall:=0;
GetStudent(CurrStudent,St,CurrWStudent);
GetQuestion(CurrStudent,Qu);
Qu1:=Qu;
Form1.Label3WSt.Caption:=WinCPToUTF8(St);
Form1.Label3WSt.Font.Color:=clRed;
Form1.Label3WSt.Font.Size:=35;
If Utf8Length(Qu) > NMax
then
begin
// S:=StringNoMore(Qu,' ',WD, NMax , RestOfStrung);
// S:=S+Chr(13)+Chr(10)+RestOfStrung;
S:=StringNoMore2(Qu,' ',WD, NMax);
S:=WinCPToUTF8(S);
// '1'+Chr(13)+Chr(10)+
// S:='Qu';
end
else S:=WinCPToUTF8(Qu);
// Writeln(LogFile,CurrStudent:2,' ',S);
Form1.Label4WQ.Caption :=S;
Form1.Label4WQ.Font.Color:=clGreen;
Form1.Label4WQ.Font.Size:=30;
// Form1.Label5N.Caption:=IntToStr(CurrStudent)+' / '+IntToStr(NumStudents);
Form1.StatusBar1.Panels[2].Text:=IntToStr(CurrStudent)+' / '+IntToStr(NumStudents);
// Writeln(LogFile,CurrStudent,' ',Qu1);
end //--------------
else
begin
MessageDlg (('Тестирование окончено'),mtInformation,[mbOk], 0);
ResultOut; // WinCPToUTF8
Form1.StatusBar1.Panels[0].Text:='';
Form1.StatusBar1.Panels[1].Text:='';
// Form1.Label2Stdnts.Caption:='';
Form1.Label3WSt.Caption:='';
Form1.Label4WQ.Caption:='';
Form1.StatusBar1.Panels[2].Text:='';
IsInputQ:=False;
IsInputS:=False;
ResultView;
// CloseFile(LogFile);
end;
end;
Procedure ResultOut;
Var FT, FT2:TextFile;
i,p:Integer; S,S2,S3,S4,DateS:String;
dt: TDateTime;
begin
dt:= Date;
DateS:=FormatDateTime('YYYY-MM-DD',dt);
p:=2;
S3:=ExtractFileNameOnly(NameQF);
S4:=ExtractFileNameOnly(NameSF);
S:=WorkDir+'\'+S3+'-'+S4+'_res.dat';
// S2:= 'd:'+'\'+S3+DateS+'_res.dat';
AssignFile(FT,S); // AssignFile(FT2,S2);
Rewrite(FT); // Rewrite(FT2);
For i:=1 to NumStudents do
begin
Writeln(FT ,TheStudents[i].Name,' ',TheStudents[i].Ball:p);
// Writeln(FT2,TheStudents[i].Name,' ',TheStudents[i].Ball:p);
end;
CloseFile(FT);
// CloseFile(FT2);
end;
Procedure ResultView;
Var i:integer;
fmt,S,S2,S3:string;
begin
S:='';
fmt:='%0:-39s';
For i:=1 to NumStudents do
begin
S3:=TheStudents[i].Name;
S2:=Format(fmt,[S3]);
S:=S+WinCPToUTF8(S2)+' '+IntToStr(TheStudents[i].Ball)+Chr(13)+Chr(10);
end;
MessageDlg ( S , mtInformation , [mbOk] , 0 ) ;
end;
Procedure GetStudent (n:integer; var st:String; var currw: integer);
Label 1;
Var i:integer;
begin
1:
i:=Random(NumStudents)+1;
If TheStudents[i].Tested then goto 1;
TheStudents[i].Tested:=True;
st:=TheStudents[i].Name;
currw:=i
end;
Procedure GetQuestion(n:integer; var qe:String);
Label 1;
Var i:integer;
begin
1:
i:=Random(NumQuestions)+1;
If TheQuestions[i].Tested then goto 1;
TheQuestions[i].Tested:=True;
qe:=TheQuestions[i].Name;
end;
begin
// AssignFile(LogFile,'D:\1.txt');
// Rewrite(LogFile);
end.