Показать сообщение отдельно
  #2  
Старый 18.03.2010, 13:23
Аватар для NIch
NIch NIch вне форума
Продвинутый
 
Регистрация: 02.06.2008
Адрес: Бендеры ПМР
Сообщения: 754
Репутация: 2446
По умолчанию

Код:
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.
__________________
В начале был Бит, потом Байт и только потом появилось Слово...
Ответить с цитированием