- •Задача 1
- •Interface
- •Implementation
- •Задача 2
- •Interface
- •Implementation
- •Задача 3
- •Задача 4
- •Implementation
- •Interface
- •Implementation
- •Var I:integer;
- •Задача 5
- •Implementation
- •Var k:integer; b,s:Extended;
- •Interface
- •Implementation
- •Interface
- •Var m:integer;
- •Implementation
- •Var X,y:Extended; I,x1,y1,xmax,ymax:Integer;
- •Задача 6
- •Implementation
- •Var k:integer; b,s:Extended;
- •Interface
- •Implementation
- •Var X,y:extended; I:integer;
- •Задача 7
- •Implementation
- •Interface
- •Implementation
- •Var x1,y1,ymax:integer;
- •Задача 9
- •Implementation
- •Interface
- •Implementation
- •Var X,y,h:extended; I:integer;
- •Задача 10
- •X1,y1,x2,y2,x3,y3,h:extended;
- •Implementation
- •Interface
- •Implementation
- •Var Xmax,ymax:integer;
- •Задача 11
- •Implementation
- •Interface
- •Implementation
- •Var tmp:string; I:integer;
- •Задача 12
- •Implementation
- •Interface
- •Implementation
- •Var I,k:integer; s:Set of char;
- •If not(st[I] in s) then
- •Include(s,st[I]);
- •Задача 13
- •Implementation
- •If savedialog1.Execute then
- •Interface
- •Implementation
- •Var ch:char;
- •Задача 14
- •Implementation
- •Interface
- •Implementation
- •Var n,i1,I:integer; tmp:string;
- •Задача 15
- •Implementation
- •If SaveDialog1.Execute then
- •Interface
- •Implementation
- •Var n:integer; ch:char;
Implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
edit1.Text:='Сколько различных символов в этой строке?';
edit2.text:='';
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
st:=Edit1.Text;
edit2.text:=IntToStr(Resh(st));
end;
end.
unit Unit2;
Interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Function Resh(st:string):integer;
Implementation
Function Resh;
Var I,k:integer; s:Set of char;
begin
S:=[]; k:=0;
for i:=1 to Length(st) do
If not(st[I] in s) then
begin
Include(s,st[I]);
k:=k+1;
end;
Result:=k;
end;
end.
Задача 13
Составить и оформить в виде отдельного модуля подпрограмму замены в текстовом файле символа (х) на символ (y)
Формальные параметры: fl : Tfl; x,y:char
Составить программу в которой c помощью компонента SaveDialog организован доступ к файлу, обращение к подпрограмме с заменой всех круглых скобок на квадратные. В качестве файла взять любую программу с расширением .pas
var
Form1: TForm1;
Fl:Tfl;
FileNameT:string;
Implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
If savedialog1.Execute then
begin
FileNameT:=SaveDialog1.FileName;
AssignFile(fl,filenamet);
Reset(fl);
end;
Resh(fl,'(','[');
seek(fl,0);
resh(fl,')',']');
CloseFile(fl);
end;
end.
unit Unit2;
Interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type Tfl=File of char;
Procedure Resh(Var fl:Tfl; x,y:Char);
Implementation
Procedure Resh;
Var ch:char;
begin
while not eof(fl) do
begin
read(fl,ch);
if ch=x then begin seek(fl,filepos(fl)-1);
write(fl,y);
end;
end;
end;
end.
Задача 14
Составить и оформить в виде отдельного модуля подпрограмму вывода в окно TEdit фрагментов текста из строки St, заключенных в квадратные скобки.
Формальные параметры: st : string; Mem : TMemo
Составить программу - обработчик события в которой при нажатии кнопки организованы ввод исходных данных из Tedit, обращение к подпрограмме, вывод исходных данных и результатов в окно TMemo.
var
Form1: TForm1;
St:string;
Implementation
{$R *.dfm}
procedure TForm1.FormCreate(Sender: TObject);
begin
Edit1.text:='Какой [фрагмент] [этого [текста] взят в основные] квадратные скобки?';
memo1.clear;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
memo1.clear;
st:=edit1.text;
resh(st,memo1);
end;
end.
unit Unit2;
Interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
Procedure Resh(st:string;memo1:tmemo);
Implementation
procedure resh;
Var n,i1,I:integer; tmp:string;
begin
n:=0; tmp:=''; i1:=0;
while i1<>length(st) do
begin
repeat
i1:=i1+1;
until (st[i1]='[') or (i1=length(st));
If i1=Length(st) then exit;
n:=n+1; i1:=i1+1;
repeat
tmp:=tmp+st[i1];
if st[i1]=']' then n:=n-1
else if st[i1]='[' then n:=n+1;
i1:=i1+1;
until n=0;
Delete(tmp,length(tmp),1);
memo1.Lines.Add(tmp);
tmp:='';
end;
end;
end.
