![]() |
|
|
|||||||
| Регистрация | << Правила форума >> | FAQ | Пользователи | Календарь | Поиск | Сообщения за сегодня | Все разделы прочитаны |
![]() |
|
|
Опции темы | Поиск в этой теме | Опции просмотра |
|
#1
|
|||
|
|||
![]() По заданию сделал 3 пункта, на 4ом больше часа тыркался, не получается. Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Math, ExtCtrls;
type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;
Memo1: TMemo;
Label1: TLabel;
Button2: TButton;
Edit3: TEdit;
Memo2: TMemo;
Button3: TButton;
Label3: TLabel;
Edit2: TEdit;
Button4: TButton;
Label5: TLabel;
GroupBox1: TGroupBox;
GroupBox2: TGroupBox;
Image1: TImage;
Image2: TImage;
Label2: TLabel;
Label4: TLabel;
Label6: TLabel;
Label7: TLabel;
GroupBox3: TGroupBox;
GroupBox4: TGroupBox;
Image3: TImage;
Label8: TLabel;
Button5: TButton;
Button6: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
procedure Button5Click(Sender: TObject);
procedure Button6Click(Sender: TObject);
// procedure Button3Click(Sender: TObject);
// procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
a:array[1..1000,1..1000] of real;
x:array[1..1000] of real;
n,m,i,j:integer;
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject); //ïîñòðîèòü ìàòðèöó
begin
memo1.clear;
n:=strtoint(edit1.Text);
for i:=1 to n do begin
memo1.lines.add(' ');
for j:=1 to n do begin
a[i,j]:=(sqr(2*i+2*j))/(exp(1/3*ln(i+j+5)));
memo1.text:=memo1.text+floattostrf(a[i,j],fffixed,8,3)+' ';
end;
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
var maxj:integer;
maxv:real;
begin
for i:=1 to n do
begin
maxv:=sqrt(a[i,1]);
for j:=1 to n do begin
if sqrt(a[i,j]) > maxv then maxv:=sqrt(a[i,j]);end;
x[i]:=maxv
end;
for i:=1 to n do
edit3.text:=edit3.text+floattostrf(X[i],fffixed,8,3)+' ';
end;
procedure TForm1.Button3Click(Sender: TObject); //ñîðòèðîâêà ïî óáûâàíèþ
var i,j,z,w :integer;
t:real;
begin
memo2.Clear;
for i:=1 to n do
for j:=i to n do
begin
if A[i,i] < A[j,j] then
begin
t:=A[i,i];
A[i,i]:=A[j,j];
A[j,j]:=t;
end;
end;
for i:=1 to n do
begin
memo2.lines.add(' ');
for j:=1 to n do
memo2.text:=memo2.text+floattostrf(a[i,j],fffixed,8,3)+' ';
end;
end;
procedure TForm1.Button4Click(Sender: TObject);
var y1,y2:real;
begin
y1:=x[i];
y2:=0;
for i:=1 to n do begin
y1:=x[1]*x[1+2];
for j:=1 to n do begin
y2:=y2+y1;
end;
edit4.Text:=floattostr(y1);
edit2.text:=floattostr(y2);
end;
END;
procedure TForm1.Button5Click(Sender: TObject);
begin
form1.Close;
end;
procedure TForm1.Button6Click(Sender: TObject);
begin
edit1.Text:=inttostr(3);
memo1.Clear;
memo2.Clear;
edit3.Clear;
edit2.clear;
end;
end.
|
|
#2
|
|||
|
|||
|
Вот кусок с 4ым пунктом
Код:
procedure TForm1.Button4Click(Sender: TObject);
var y1,y2:real;
begin
y1:=x[i];
y2:=0;
for i:=1 to n do begin
y1:=x[1]*x[1+2];
for j:=1 to n do begin
y2:=y2+y1;
end;
edit4.Text:=floattostr(y1);
edit2.text:=floattostr(y2);
end;
END; |
|
#3
|
|||
|
|||
|
После создания вектора Х, элемент х[i] почему то оказываеться последним, как считать с 1го элемента?
|
|
#4
|
||||
|
||||
|
Это как понять?
Код:
procedure TForm1.Button4Click(Sender: TObject);
var y1,y2:real;
begin
y1:=x[i];
y2:=0;
for i:=1 to n do begin
y1:=x[1]*x[1+2];
for j:=1 to n do begin
y2:=y2+y1;
end;
edit4.Text:=floattostr(y1);
edit2.text:=floattostr(y2);
end;
END; |
|
#5
|
|||
|
|||
|
Изначально было y1=1, потом менял, пробывал по другому несколько раз.
|
|
#6
|
|||
|
|||
|
Цитата:
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
OpenDialog1: TOpenDialog;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
const
//buffer, inache zavisaet
BLenMax = 100000;
//mnozhestvo russkih bukv
D = ['À'..'Ï', 'Ð'..'ß', '¨'];
var
F : File;
Buff : array of Char;
AStat : array[Char] of Integer;
Ch : Char;
i, BLenRes : Integer;
razi : string;
begin
if OpenDialog1.InitialDir = '' then
OpenDialog1.InitialDir := ExtractFilePath( Application.ExeName )
;
if not OpenDialog1.Execute then Exit;
if not FileExists(Opendialog1.FileName) then begin
MessageDlg(
'ôàéë ñ òàêèì èìåíåì íå íàéäåí',
mtWarning, [mbOk], 0
);
Exit;
end;
//obnilyaem massiv
for Ch := #0 to #255 do AStat[Ch] := 0;
SetLength(Buff, BLenMax);
//Open and read selected file
AssignFile(F, OpenDialog1.FileName);
Reset(F, 1);
while not Eof(F) do begin
BlockRead(F, Pointer(Buff)^, BLenMax, BLenRes);
for i := 0 to BLenRes - 1 do begin
Ch := AnsiUpperCase(Buff[i])[1];
Inc(AStat[Ch]);
end;
end;
CloseFile(F);
//vivod v memo1
Memo1.Lines.Add('Èñïîëüçîâà 37;û áóêâû:');
for Ch := #0 to #255 do begin
if not (Ch in D) then Continue;
Memo1.Lines.Add('Буква: "' + Ch + '", использована = ' + IntToStr(AStat[Ch]));
end;
end;
end. |
|
#7
|
||||
|
||||
|
Цитата:
|
|
#8
|
|||
|
|||
|
Цитата:
Предложили вставить вот такую функцию, но с ней всегда пишет раз Код:
function EhRazEscheRazEscheMnogoMnogoRaz(N: cardinal): string; begin if (N in [5..21]) or ((N mod 10) in [0, 1, 5..9]) then Result := 'раз'; else Result := 'раза'; end; Вот что получилось, может где ошибься. Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
OpenDialog1: TOpenDialog;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
function RaziliRazi(N: cardinal): string;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.RaziliRazi(N: cardinal): string;
begin
if (N in [5..21]) or ((N mod 10) in [0, 1, 5..9]) then
Result := 'раз'
else
Result := 'раза';
end;
procedure TForm1.Button1Click(Sender: TObject);
const
//buffer, inache zavisaet
BLenMax = 100000;
//mnozhestvo russkih bukv
D = ['À'..'Ï', 'Ð'..'ß', '¨'];
var
F : File;
Buff : array of Char;
AStat : array[Char] of Integer;
Ch : Char;
n, i, BLenRes : Integer;
begin
if OpenDialog1.InitialDir = '' then
OpenDialog1.InitialDir := ExtractFilePath( Application.ExeName )
;
if not OpenDialog1.Execute then Exit;
if not FileExists(Opendialog1.FileName) then begin
MessageDlg(
'нет файла',
mtWarning, [mbOk], 0
);
Exit;
end;
//obnilyaem massiv
for Ch := #0 to #255 do AStat[Ch] := 0;
SetLength(Buff, BLenMax);
//Open and read selected file
AssignFile(F, OpenDialog1.FileName);
Reset(F, 1);
while not Eof(F) do begin
BlockRead(F, Pointer(Buff)^, BLenMax, BLenRes);
for i := 0 to BLenRes - 1 do begin
Ch := AnsiUpperCase(Buff[i])[1];
Inc(AStat[Ch]);
end;
end;
CloseFile(F);
//vivod v memo1
Memo1.Lines.Add('Èñïîëüçîâàíû áóêâû:');
for Ch := #0 to #255 do begin
if not (Ch in D) then Continue;
Memo1.Lines.Add('Буква: "' + Ch + '", использована = ' + IntToStr(AStat[Ch])+' '+RaziliRazi(N));
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
form1.close;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
memo1.Clear;
end;
end. |
|
#9
|
||||
|
||||
|
Возможно я что то не понимаю, но где вычисляется переменная N:
Код:
Memo1.Lines.Add('Буква: "' + Ch + '", использована = ' + IntToStr(AStat[Ch])+' '+RaziliRazi(N));Последний раз редактировалось angvelem, 10.12.2011 в 22:28. |
|
#10
|
|||
|
|||
|
Цитата:
Что то я не пойму как я вычеслять, то есть после чего цикл вставить. |
|
#11
|
||||
|
||||
|
Надеюсь не напутал:
Код:
//obnilyaem massiv
// for Ch := #0 to #255 do AStat[Ch] := 0;
// так проще
FillChar(AStat, SizeOf(AStat), 0);
...
Memo1.Lines.Add('Буква: "' + Ch + '", использована = ' + IntToStr(AStat[Ch]) + ' ' + RaziliRazi(AStat[Ch])); |
|
#12
|
|||
|
|||
|
Цитата:
Спасибо большое, теперь будем разбираться и дальше читать книги. Все работает. Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
OpenDialog1: TOpenDialog;
Button2: TButton;
Button3: TButton;
procedure Button1Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
function RaziliRazi(N: cardinal): string;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function TForm1.RaziliRazi(N: cardinal): string;
begin
if (N in [5..21]) or ((N mod 10) in [0, 1, 5..9]) then
Result := 'раз'
else
Result := 'раза';
end;
procedure TForm1.Button1Click(Sender: TObject);
const
//buffer, inache zavisaet
BLenMax = 100000;
//mnozhestvo russkih bukv
D = ['А'..'П', 'Р'..'Я', 'Ё'];
battle: array[0..2] of string=(' ðàç',' ðàç',' ðàçà');
var
F : File;
Buff : array of Char;
AStat : array[Char] of Integer;
Ch : Char;
i, BLenRes : Integer;
begin
if OpenDialog1.InitialDir = '' then
OpenDialog1.InitialDir := ExtractFilePath( Application.ExeName )
;
if not OpenDialog1.Execute then Exit;
if not FileExists(Opendialog1.FileName) then begin
MessageDlg(
'Файл не найден',
mtWarning, [mbOk], 0
);
Exit;
end;
//obnгlyaem massiv
for Ch := #0 to #255 do AStat[Ch] := 0;
SetLength(Buff, BLenMax);
//Open and read selected file
AssignFile(F, OpenDialog1.FileName);
Reset(F, 1);
while not Eof(F) do begin
BlockRead(F, Pointer(Buff)^, BLenMax, BLenRes);
for i := 0 to BLenRes - 1 do begin
Ch := AnsiUpperCase(Buff[i])[1];
Inc(AStat[Ch]);
end;
end;
CloseFile(F);
//vivod v memo1
Memo1.Lines.Add('Использованы буквы:');
for Ch := #0 to #255 do begin
if not (Ch in D) then Continue;
Memo1.Lines.Add('Буква: "' + Ch + '", использована = ' + IntToStr(AStat[Ch]) + ' ' + RaziliRazi(AStat[Ch]));
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
form1.close;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
memo1.Clear;
end;
end. |
|
#13
|
||||
|
||||
|
Замени:
Код:
for Ch := #0 to #255 do AStat[Ch] := 0; Код:
FillChar(AStat, SizeOf(AStat), 0); ![]() |
|
#14
|
|||
|
|||
|
Цитата:
Читал про эту процедуру и забыл пост обновить c программой ![]() |
|
#15
|
|||
|
|||
|
не подскажите, как продолжить этот код, чтобы он показывал % использования каждой буквы от общей суммы
|