![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#1
|
|||
|
|||
|
условие:Описать процедуру DoubleX(A,N,X), дублирующую элементы, равные X, в массиве A целых чисел рахмера N. Массив A и число N являются входными и выходными параметрами. С помощью этой процедуры продублировать в массивах A,B,C размера NA,NB,NC каждое вхождение чисел XA,XB,XC соответственно.
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
StringGrid1: TStringGrid;
Label2: TLabel;
Edit2: TEdit;
Button2: TButton;
StringGrid2: TStringGrid;
Label3: TLabel;
Edit3: TEdit;
Button3: TButton;
StringGrid3: TStringGrid;
Button4: TButton;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Edit4: TEdit;
Label8: TLabel;
Edit5: TEdit;
Label9: TLabel;
Edit6: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
type myarr = array of real;
implementation
{$R *.dfm}
procedure DoubleX(var A: myarr; var N: integer; X: real);
var i,j, num: integer;
tempmas: myarr;
begin
num := 0;
for I := 0 to N - 1 do
if A[i] = x then inc(num);
setlength(tempmas, N+num);
j := 0 ;
for I := 0 to N - 1 do begin
tempmas[j] := A[i];
inc(j);
if a[i] = x then begin
tempmas[j] := a[i];
inc(j);
end;
end;
a := tempmas;
n := n+num;
end;
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
randomize;
StringGrid1.ColCount := strtoint(edit1.text);
for I := 0 to StringGrid1.ColCount - 1 do
StringGrid1.Cells[i,0] := floattostr(round(random*255));
end;
procedure TForm1.Button2Click(Sender: TObject);
var i:integer;
begin
randomize;
StringGrid2.ColCount := strtoint(edit2.text);
for I := 0 to StringGrid2.ColCount - 1 do
StringGrid2.Cells[i,0] := floattostr(round(random*255));
end;
procedure TForm1.Button3Click(Sender: TObject);
var i:integer;
begin
randomize;
StringGrid3.ColCount := strtoint(edit3.text);
for I := 0 to StringGrid3.ColCount - 1 do
StringGrid3.Cells[i,0] := floattostr(round(random*255));
end;
procedure TForm1.Button4Click(Sender: TObject);
var a,b,c: myarr;
a1,b1,c1,i: integer;
begin
setlength(a,StringGrid1.ColCount);
SetLength(b,StringGrid2.ColCount);
SetLength(c,StringGrid3.ColCount);
for I := 0 to StringGrid1.ColCount - 1 do
a[i] := strtofloat(StringGrid1.cells[i,0]);
for I := 0 to StringGrid2.ColCount - 1 do
b[i] := strtofloat(StringGrid2.cells[i,0]);
for I := 0 to StringGrid3.ColCount - 1 do
c[i] := strtofloat(StringGrid3.cells[i,0]);
i:= stringgrid1.colcount;
doublex(a, i, strtofloat(edit4.Text));
StringGrid1.ColCount := i;
i:= stringgrid2.colcount;
doublex(b, i, strtofloat(edit5.Text));
StringGrid2.ColCount := i;
i:= stringgrid3.colcount;
doublex(c, i, strtofloat(edit6.Text));
StringGrid3.ColCount := i;
for I := 0 to StringGrid1.ColCount - 1 do
stringgrid1.Cells[i,0] := floattostr(a[i]);
for I := 0 to StringGrid2.ColCount - 1 do
stringgrid2.Cells[i,0] := floattostr(b[i]);
for I := 0 to StringGrid3.ColCount - 1 do
stringgrid3.Cells[i,0] := floattostr(c[i]);
end;
end.Последний раз редактировалось Admin, 18.03.2010 в 12:16. |
|
#2
|
||||
|
||||
|
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
//Объявление твоей формы
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
StringGrid1: TStringGrid;
Label2: TLabel;
Edit2: TEdit;
Button2: TButton;
StringGrid2: TStringGrid;
Label3: TLabel;
Edit3: TEdit;
Button3: TButton;
StringGrid3: TStringGrid;
Button4: TButton;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label7: TLabel;
Edit4: TEdit;
Label8: TLabel;
Edit5: TEdit;
Label9: TLabel;
Edit6: TEdit;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;//Переменная формы
type myarr = array of real;//тип массив чисел
implementation
{$R *.dfm}
procedure DoubleX(var A: myarr; var N: integer; X: real);
var i,j, num: integer;
tempmas: myarr;//переменная массив чисел
begin
num := 0;
//от 0 до N делать
for I := 0 to N - 1 do
//если i-ый элемент массива равен x то увеличить Num
if A[i] = x then inc(num);
//Услтановать величину массива tempmas
setlength(tempmas, N+num);
j := 0 ;
//от 0 до N делать
for I := 0 to N - 1 do begin
//приравнять массив tempmas
tempmas[j] := A[i];
inc(j);
//Если i-ый элемент массива а равен х
if a[i] = x then begin
//То j-ый элемент приравниваем i-тому а
tempmas[j] := a[i];
inc(j);
end;
end;
a := tempmas;
n := n+num;
end;
//Нажатие на кнопку 1
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
//генератор случайных чисел
randomize;
//установка числа столбцов в таблице из Edit1
StringGrid1.ColCount := strtoint(edit1.text);
//до конца столбцов заполнить случайно первую строку до 255
for I := 0 to StringGrid1.ColCount - 1 do
StringGrid1.Cells[i,0] := floattostr(round(random*255));
end;
//Тоже самое но таблица 2
procedure TForm1.Button2Click(Sender: TObject);
var i:integer;
begin
randomize;
StringGrid2.ColCount := strtoint(edit2.text);
for I := 0 to StringGrid2.ColCount - 1 do
StringGrid2.Cells[i,0] := floattostr(round(random*255));
end;
//Тоже самое но таблица 3
procedure TForm1.Button3Click(Sender: TObject);
var i:integer;
begin
randomize;
StringGrid3.ColCount := strtoint(edit3.text);
for I := 0 to StringGrid3.ColCount - 1 do
StringGrid3.Cells[i,0] := floattostr(round(random*255));
end;
procedure TForm1.Button4Click(Sender: TObject);
var
a,b,c: myarr;//массивы
a1,b1,c1,i: integer;
begin
//Заполнить массивы а b c данными из 3-х таблиц
setlength(a,StringGrid1.ColCount);
SetLength(b,StringGrid2.ColCount);
SetLength(c,StringGrid3.ColCount);
for I := 0 to StringGrid1.ColCount - 1 do
a[i] := strtofloat(StringGrid1.cells[i,0]);
for I := 0 to StringGrid2.ColCount - 1 do
b[i] := strtofloat(StringGrid2.cells[i,0]);
for I := 0 to StringGrid3.ColCount - 1 do
c[i] := strtofloat(StringGrid3.cells[i,0]);
//С каждым массивом проделать процедуру DoubleX
i:= stringgrid1.colcount;
doublex(a, i, strtofloat(edit4.Text));
StringGrid1.ColCount := i;
i:= stringgrid2.colcount;
doublex(b, i, strtofloat(edit5.Text));
StringGrid2.ColCount := i;
i:= stringgrid3.colcount;
doublex(c, i, strtofloat(edit6.Text));
StringGrid3.ColCount := i;
//Заполнить таблицы данными из 2- массивов
for I := 0 to StringGrid1.ColCount - 1 do
stringgrid1.Cells[i,0] := floattostr(a[i]);
for I := 0 to StringGrid2.ColCount - 1 do
stringgrid2.Cells[i,0] := floattostr(b[i]);
for I := 0 to StringGrid3.ColCount - 1 do
stringgrid3.Cells[i,0] := floattostr(c[i]);
end;
end. |
|
#3
|
|||
|
|||
|
а если я еще напишу задачки, вы мне коментарии не подпишите?очень прошу...ну не понимаю я...
|
|
#4
|
|||
|
|||
|
укажи, где именно не понятно. Каждую строку никто комментировать не возьмется.
не думаю, что сложность вызывает "for I := 0 to N - 1 do " и т.п. |
|
#5
|
||||
|
||||
|
Цитата:
Вопрос...а откуда задачки то??? |
|
#6
|
|||
|
|||
|
мне задачи сдать надо, а я если честно не умею их решать, вот и мучаюсь...а с коментариями я хоть что то сказать смогу...(((
|
|
#7
|
||||
|
||||
|
Дерзай)))))
|
|
#8
|
|||
|
|||
|
а на счет комментариев, ну конечно же ни к каждой строчке, просто самое основное...ну что бы только понятно было..
|
|
#9
|
|||
|
|||
|
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Grids;
type
TForm1 = class(TForm)
StringGrid1: TStringGrid;
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
temp,temp1:string;
begin
if(StringGrid1.ColCount mod 2 = 1) then
temp1 := StringGrid1.Cells[StringGrid1.colcount-1,0];
for i := 0 to stringgrid1.ColCount div 2 do begin
temp := stringgrid1.Cells[2*i,0];
StringGrid1.Cells[2*i,0]:= StringGrid1.Cells[2*i+1,0];
StringGrid1.Cells[2*i+1,0] := temp;
end;
if(StringGrid1.ColCount mod 2 = 1) then
StringGrid1.Cells[StringGrid1.colcount-1,0] := temp1;
end;
procedure TForm1.Button2Click(Sender: TObject);
var i:integer;
begin
randomize;
for i:= 0 to StringGrid1.ColCount-1 do
StringGrid1.Cells[i,0] := inttostr(random(128));
end;
end.Последний раз редактировалось Admin, 18.03.2010 в 14:59. |
|
#10
|
|||
|
|||
|
условие:1. В произвольном массиве поменяйте местами соседние четные и нечетные по номеру элементы. Дополнительные массивы не использовать.
|
|
#11
|
|||
|
|||
|
Описать процедуру MoveLeft (A,N,K) (MoveRight (A,N,K)), осуществляющую циклический сдвиг элементов вещественного массива A размера N на k позиций влево (вправо) (0<k<5,k<N). Массив A- входной и выходнолй параметр, N и k входные параметры. С помощью этой процедуры осуществить сдвиг элементов данного массива размера N на k1 позиций, а затем - сдвиг элементов полученного массива на k2 позиций (k1и k2даны). После каждого вызова процедуры выводить на экран результирующий массив.
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, Grids, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Edit1: TEdit;
Button1: TButton;
StringGrid1: TStringGrid;
Button4: TButton;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
Label2: TLabel;
Edit2: TEdit;
Label3: TLabel;
Edit3: TEdit;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure moveleft(var A:array of real; n,k:integer);
var iq, jq,i,j:integer;
temp, temp2 : array of real;
begin
iq := k mod n; // k
jq := n - iq; // n-k
setlength(temp,iq);
setlength(temp2,jq);
for I := 0 to iq - 1 do
temp[i] := A[i];
for I := 0 to jq - 1 do
temp2[i] := A[i+iq];
for I := 0 to jq - 1 do
A[i] := temp2[i];
for I := 0 to iq - 1 do
A[i+jq] := temp[i];
end;
procedure moveright(var A:array of real; n,k:integer);
var iq, jq,i,j:integer;
temp, temp2 : array of real;
begin
iq := k mod n; // k
jq := n - iq; // n-k
setlength(temp,iq);
setlength(temp2,jq);
for I := 0 to iq - 1 do
temp[i] := A[i+jq];
for I := 0 to jq - 1 do
temp2[i] := A[i];
for I := 0 to jq - 1 do
A[i+iq] := temp2[i];
for I := 0 to iq - 1 do
A[i] := temp[i];
end;
procedure TForm1.Button1Click(Sender: TObject);
var i:integer;
begin
randomize;
StringGrid1.ColCount := strtoint(edit1.text);
for I := 0 to StringGrid1.ColCount - 1 do
StringGrid1.Cells[i,0] := floattostr(round(random*255));
end;
procedure TForm1.Button2Click(Sender: TObject);
var a,b,c: array of real;
a1,b1,c1,i: integer;
begin
setlength(a,StringGrid1.ColCount);
for I := 0 to StringGrid1.ColCount - 1 do
a[i] := strtofloat(StringGrid1.cells[i,0]);
// moveleft(a,StringGrid1.ColCount, strtoint(edit2.text));
moveright(a,StringGrid1.ColCount, strtoint(edit3.text));
for I := 0 to StringGrid1.ColCount - 1 do
stringgrid1.Cells[i,0] := floattostr(a[i]);
end;
procedure TForm1.Button4Click(Sender: TObject);
var a,b,c: array of real;
a1,b1,c1,i: integer;
begin
setlength(a,StringGrid1.ColCount);
for I := 0 to StringGrid1.ColCount - 1 do
a[i] := strtofloat(StringGrid1.cells[i,0]);
moveleft(a,StringGrid1.ColCount, strtoint(edit2.text));
// moveright(a,StringGrid1.ColCount, strtoint(edit3.text));
for I := 0 to StringGrid1.ColCount - 1 do
stringgrid1.Cells[i,0] := floattostr(a[i]);
end;
end. |