unit
Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 =
class
(TForm)
Label1: TLabel;
Button1: TButton;
Button2: TButton;
Button3: TButton;
ListBox1: TListBox;
StringGrid1: TStringGrid;
Edit1: TEdit;
Label2: TLabel;
ListBox2: TListBox;
Label3: TLabel;
Button4: TButton;
Label4: TLabel;
ListBox3: TListBox;
Label5: TLabel;
ListBox4: TListBox;
procedure
Button1Click(Sender: TObject);
procedure
Button2Click(Sender: TObject);
procedure
FormCreate(Sender: TObject);
procedure
Button3Click(Sender: TObject);
procedure
Button4Click(Sender: TObject);
private
public
end
;
type
mark=(gz,mz,uz,vz,lz,kz,zl,kr,tt,fr);
mnz=
set
of
mark;
const
naz:
array
[mark]
of
string
=(
'ГАЗ'
,
'МАЗ'
,
'УАЗ'
,
'ВАЗ'
,
'ЛАЗ'
,
'КамАЗ'
,
'ЗИЛ'
,
'КрАЗ'
,
'ТАТРА'
,
'ФОРД'
);
var
Form1: TForm1;
a:
array
of
mnz;
n:
integer
;
mn:
integer
;
implementation
{$R *.dfm}
procedure
TForm1
.
FormCreate(Sender: TObject);
var
i:mark;
begin
with
ListBox1
do
begin
for
i:=gz
to
fr
do
Items
.
Add(naz[i]);
ExtendedSelect:=
false
;
MultiSelect:=
true
;
end
;
Button1
.
Enabled:=
true
;
Button2
.
Enabled:=
false
;
Button3
.
Enabled:=
false
;
Button4
.
Enabled:=
false
;
with
StringGrid1
do
begin
fixedrows:=
1
;
fixedcols:=
0
;
rowcount:=ord(fr)+
1
;
end
;
end
;
procedure
TForm1
.
Button1Click(Sender: TObject);
var
k:
integer
;
begin
val
(Edit1
.
Text,n,k);
if
(k<>
0
)
or
not
(n
in
[
3..10
])
then
begin
ShowMessage(
'Неверно введено количество цехов'
);
Edit1
.
Clear;
Edit1
.
SetFocus;
exit;
end
;
setlength(a,n);
with
StringGrid1
do
begin
colcount:=n;
for
k:=
0
to
n-
1
do
cells[k,
0
]:=
'Цех '
+inttostr(k+
1
);
end
;
Button1
.
Enabled:=
false
;
Button2
.
Enabled:=
true
;
end
;
procedure
TForm1
.
Button2Click(Sender: TObject);
var
i:
byte
;
begin
inc(mn);
for
i:=
0
to
ListBox1
.
Count-
1
do
ListBox1
.
Selected[i]:=
false
;
Showmessage(
'Выберите продукты для множества '
+inttostr(mn));
Button2
.
Enabled:=
false
;
Button3
.
Enabled:=
true
;
end
;
procedure
TForm1
.
Button3Click(Sender: TObject);
var
i,j:
byte
;
k:mark;
begin
a[mn-
1
]:=[];
for
i:=
0
to
Listbox1
.
Count-
1
do
if
Listbox1
.
Selected[i]
then
a[mn-
1
]:=a[mn-
1
]+[mark(i)];
j:=
0
;
for
k:=gz
to
fr
do
if
k
in
a[mn-
1
]
then
begin
inc(j);
StringGrid1
.
Cells[mn-
1
,j]:=naz[k];
end
;
Button2
.
Enabled:=
true
;
Button3
.
Enabled:=
false
;
if
mn=n
then
begin
Button2
.
Enabled:=
false
;
Button3
.
Enabled:=
false
;
Button4
.
Enabled:=
true
;
end
;
end
;
procedure
TForm1
.
Button4Click(Sender: TObject);
var
k:mark;
f1,f2,f3,w,i:
byte
;
begin
f1:=
0
;
f2:=
0
;
f3:=
0
;
for
k:=gz
to
fr
do
begin
w:=
0
;
for
i:=
0
to
n-
1
do
if
k
in
a[i]
then
w:=w+
1
;
if
w=
0
then
begin
f3:=
1
;
ListBox4
.
Items
.
Add(naz[k]);
end
else
if
w=n
then
begin
ListBox2
.
Items
.
Add(naz[k]);
f1:=
1
;
end
else
if
w>
0
then
begin
ListBox3
.
Items
.
Add(naz[k]);
f2:=
1
;
end
;
end
;
if
f1=
0
then
ListBox2
.
Items
.
Add(
'Таких марок нет!'
);
if
f2=
0
then
ListBox3
.
Items
.
Add(
'Таких марок нет!'
);
if
f3=
0
then
ListBox4
.
Items
.
Add(
'Таких марок нет!'
)
end
;
end
.