Форум по Delphi программированию

Delphi Sources



Вернуться   Форум по Delphi программированию > Все о Delphi > [ "Начинающим" ]
Ник
Пароль
Регистрация <<         Правила форума         >> FAQ Пользователи Календарь Поиск Сообщения за сегодня Все разделы прочитаны

 
 
Опции темы Поиск в этой теме Опции просмотра
  #1  
Старый 18.03.2010, 12:11
Мария Мария вне форума
Прохожий
 
Регистрация: 14.03.2010
Сообщения: 14
Репутация: 10
По умолчанию вы не могли бы написать комментарии к задаче, а то я не понимаю ни фига...

условие:Описать процедуру DoubleX(A,N,X), дублирующую элементы, равные X, в массиве A целых чисел рахмера N. Массив A и число N являются входными и выходными параметрами. С помощью этой процедуры продублировать в массивах A,B,C размера NA,NB,NC каждое вхождение чисел XA,XB,XC соответственно.
Код:
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
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: Пользуемся тегами!

Последний раз редактировалось Admin, 18.03.2010 в 12:16.
Ответить с цитированием
 


Delphi Sources

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск
Опции просмотра

Ваши права в разделе
Вы не можете создавать темы
Вы не можете отвечать на сообщения
Вы не можете прикреплять файлы
Вы не можете редактировать сообщения

BB-коды Вкл.
Смайлы Вкл.
[IMG] код Вкл.
HTML код Выкл.
Быстрый переход


Часовой пояс GMT +3, время: 13:14.


 

Сайт

Форум

FAQ

Соглашения

Прочее

 

Copyright © Форум "Delphi Sources" by BrokenByte Software, 2004-2025