Задача:
Фамилия Имя Факультативы
Мат. Физ. Инф.
Павлов Серг true false true
Мисюченко Ира true true false
Сидорон Зоя false false true
Кладов Роман true false false
Создайте массив следующего содержания и структуры, выведите фамилии и имена школьников, которые не посещают факультатив по физике или по математике.
Var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
StringGrid1.Cells[1,1] := 'Фамилия ';
StringGrid1.Cells[2,1] := 'Имя';
StringGrid1.Cells[3,1] := 'математика';
StringGrid1.Cells[4,1] := 'физика';
StringGrid1.Cells[5,1] := 'информатика';
StringGrid1.Cells[1,2] := 'Иванов';
StringGrid1.Cells[2,2] := 'Коля';
StringGrid1.Cells[3,2] := 'да';
StringGrid1.Cells[4,2] := 'да';
StringGrid1.Cells[5,2] := 'нет';
StringGrid1.Cells[1,3] := 'Петров';
StringGrid1.Cells[2,3] := 'Вася';
StringGrid1.Cells[3,3] := 'да';
StringGrid1.Cells[4,3] := 'да';
StringGrid1.Cells[5,3] := 'да';
end;
procedure TForm1.Button2Click(Sender: TObject);
var i,j:integer;
begin
for j:=2 to 3 do begin
for i:=1 to 4 do
if (StringGrid1.Cells[3,j]= 'нет') or (StringGrid1.Cells[4,j]= 'нет') then
StringGrid1.Cells[1,j]:= StringGrid1.Cells[1,j];
StringGrid1.Cells[2,j]:= StringGrid1.Cells[2,j];
end;end;
procedure TForm1.Button3Click(Sender: TObject);
var i,j:integer;
begin
for j:=2 to 3 do begin
for i:=1 to 4 do
StringGrid1.Cells[1,j]:='';
StringGrid1.Cells[2,j]:= '';
StringGrid1.Cells[3,j] := '';
StringGrid1.Cells[4,j] := '';
StringGrid1.Cells[5,j] := '';end;
end;
end.
А почему ты в RunTime создаешь массив, а не на этапе компиляции?
var
arr: array[1 .. 4] of record
name: string[50];
math, phys, info: boolean;
end = (
(name:'Павлов Серг'; math:true; phys:false; info:true ),
(name:'Мисюченко Ира'; math:true; phys:true; info:false),
(name:'Сидорон Зоя'; math:false; phys:false; info:true ),
(name:'Кладов Роман'; math:true; phys:false; info:false)
);
Это я додумала 1-й вариант своей задачи со 2-й кнопкой. Кривовато, но работает.
procedure TForm1.Button2Click(Sender: TObject);
var i,j:integer;
begin
for j:=2 to 3 do begin
for i:=1 to 4 do
begin
if (StringGrid1.Cells[3,j]= 'нет') or (StringGrid1.Cells[4,j]= 'нет') then
begin
StringGrid1.Cells[1,j]:= StringGrid1.Cells[1,j];
StringGrid1.Cells[2,j]:= StringGrid1.Cells[2,j];
StringGrid1.Cells[3,j]:= '';
StringGrid1.Cells[4,j]:= '';
StringGrid1.Cells[5,j]:= '';end;
if (StringGrid1.Cells[3,j]= 'да') and (StringGrid1.Cells[4,j]= 'да') then
begin
StringGrid1.Cells[1,j]:= '';
StringGrid1.Cells[2,j]:= '';
StringGrid1.Cells[3,j]:= '';
StringGrid1.Cells[4,j]:= '';
StringGrid1.Cells[5,j]:= '';
end;end;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
i:integer;
x: array[1 .. 4] of record
name: string[50];
math, phys, info: boolean;
end = ( {выделяет эту строку}
(name:'Павлов Серг'; math:true; phys:false; info:true ),
(name:'Мисюченко Ира'; math:true; phys:true; info:false),
(name:'Сидорон Зоя'; math:false; phys:false; info:true ),
(name:'Кладов Роман'; math:true; phys:false; info:false)
);
begin
for i:=1 to 4 do
if (x[i].math=false) or (x[i].phys=false) then
with x[i] do
StringGrid1.Cells[i] :=x[i].name;
end;
end.
Ага... Правильно... Переменная X должна быть либо Var, но глобально (вне процедуры), либо можно локально (прямо внутри процедуры), но только с Const ...
with x[i] do
StringGrid1.Cells[i] :=x[i].name;
StringGrid1.Cells[i] :=x[i].x[i].name;
with x[i] do
StringGrid1.Cells[i] :=x[i].name;
StringGrid1.Cells[i] :=x[i].x[i].name;
stringgrid1.cells[1,i]:=x[i].x[i].name;
stringgrid1.cells[1,i]:=x[i].name;
ты последовательно обращаешься к элементам
что такое x[i].x[i] компилятор не может понять...
а вот почему не идет
stringgrid1.cells[1,i]:=x[i].name;- не могу сходу сказать. может, до этого что-то не то?
stringgrid1.cells[1,i]:=x[i].name;
можешь прикрепить проект?
в архиве... все, кроме ехе-шника
131____________.zip ( 7.33 килобайт )
Кол-во скачиваний: 403
выводит... но ты этого не видишь, так как выводит в первый столбец (а у тебя только нулевой).
вот так работает:
for i:=1 to 4 do
if not(x[i].math) or not(x[i].phys) then
stringgrid1.cells[0,i]:=x[i].name;
Спасибо. Я все поняла. Выводится сообщения начались, но с "дырками". Я попыталась исправить ситуацию, изменив вот так код:
procedure TForm1.Button1Click(Sender: TObject);
var
i,j,n,k:integer;
y:array[1..4] of record
name1:string[50]; end;
const x: array[1 .. 4] of record
name: string[50];
math, phys, info: boolean;
end = (
(name:'Павлов Серг'; math:true; phys:false; info:true ),
(name:'Мисюченко Ира'; math:true; phys:true; info:false),
(name:'Сидорон Зоя'; math:false; phys:false; info:true ),
(name:'Кладов Роман'; math:true; phys:false; info:false)
);
begin
n:=0;
for i:=1 to 4 do
begin
k:=0;
if not(x[i].math) or not(x[i].phys) then
begin
stringgrid1.cells[0,i]:=x[i].name;
k:=k+1;
if k=1 then begin n:=n+1; y[n].name1:=x[i].name;end;{создаю в отдельную запись правильные ответы}
end;
end;
for i:=1 to 4 do begin {вывожу отдельную запись}
stringgrid1.cells[0,i]:=y[i].name1; end;
end;
end.
а зачем такие сложности?
дополнительный массив...
k:=1;
for i:=1 to 4 do
if not(x[i].math) or not(x[i].phys) then
begin
stringgrid1.cells[0,k]:=x[i].name;
inc(k);
end;
y[i].name1:=''
Большое спасибо за помощь!