TEmc=class
m,c:integer;
constructor input (newm,newc:integer);
function ABC(Emc:TEmc):integer;
end;
var
Form1: TForm1;
x1,x2:string; e,i: Integer;
implementation
procedure TForm1.Button1Click(Sender: TObject);
begin
for i:= 0 to 20 do begin
ListBox1.Items[i]:=inttostr(random(10));
ListBox2.Items[i]:=inttostr(random(10));
end; end;
procedure TForm1.Button2Click(Sender: TObject);
var Emc1:TEmc;
begin
Emc1:=TEmc.input(strtoint(ListBox1.Items[listbox1.Itemindex]),strtoint(ListBox2.Items[listbox2.Itemindex]));
Edit1.Text:=inttostr(Emc1.ABC(Emc1));
end;
procedure TForm1.ListBox2Click(Sender: TObject);
begin
x2:=ListBox1.Items[listbox1.Itemindex];
end;
function TEmc.ABC(Emc: TEmc): integer;
begin
Result:=m*sqr(c);
end;
constructor TEmc.input(newm, newc: integer);
begin
m:=newm; c:=newc;
end;
end.
TPhysic = class
restype:string;
r:real;
function Vychislenie (Res:TPhysic):real;
constructor Input (newr:real;newrestype:string);
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
{ TPhysic }
constructor TPhysic.Input(newr: real; newrestype: string);
begin
r:=newr;
restype:=newrestype;
end;
function TPhysic.Vychislenie(Res: TPhysic): real;
begin
if (restype='consistent') or (res.restype='consistent')
then Result:=r+Res.r
else Result:=(r+Res.r)/(r*Res.r);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Res1,Res2:TPhysic;
begin
Res1:=TPhysic.Input(strtofloat(Edit1.Text),Edit3.Text);
Res2:=TPhysic.Input(strtofloat(Edit2.Text),Edit3.Text);
if Edit3.Text='consistent' then
showmessage('Сопротивление R при последовательном соединении = '+floattostr(Res1.Vychislenie(Res2)))
else showmessage('Сопротивление R при парралельном соединении = '+floattostr(Res1.Vychislenie(Res2)))
end;
end.
Приложени 1. Работа с массивами…
var
a:array[0..10] of integer;
s,max,min:integer; i:integer;
// двумерный
b:array[1..3,1..3] of integer;
k,l,n:integer;
procedure TForm1.FormCreate(Sender: TObject);
begin
// заполнение одномерного массива
randomize;
for i:=0 to 10 do begin
a[i]:=random(10);
end;
// вывод на экран квадратов нечетных значений элементов
for i:=0 to 10 do begin
ListBox1.Items[i]:=inttostr(a[i]);
if a[i] mod 2=1 then
ListBox2.Items[i]:=inttostr(a[i]*a[i]) else ListBox2.Items[i]:='';
end;
// поиск и вывод максимального и минимального элемента
max:=a[1];
min:=a[1];
for i:=0 to 10 do if a[i]> max then max:=a[i];
Label7.Caption:=inttostr(max);
for i:=0 to 10 do if a[i]< min then min:=a[i];
Label8.Caption:=inttostr(min);
end;
procedure TForm1.Button1Click(Sender: TObject);
// заполнение двумерного массива
begin
for k:=1 to 3 do
for l:=1 to 3 do begin
b[k,l]:=random(50);
StringGrid1.Cells[k-1,l-1]:=inttostr(b[k,l]);
end;
end;
procedure TForm1.Button2Click(Sender: TObject);
// нахождение суммы главной диагонали в массиве
begin
s:=0;
for k:=1 to 3 do
s:=s+strtoint(StringGrid1.Cells[k-1,k-1]);
Label3.Caption:=inttostr(s);
end;
procedure TForm1.Button3Click(Sender: TObject);
// нахождение суммы побочной диагонали в массиве
begin
s:=0;
n:=3;
for k:=1 to n do
s:=s+strtoint(StringGrid1.Cells[k-1,(n-1)+1-k]);
Label4.Caption:=inttostr(s);
end;
procedure TForm1.Button4Click(Sender: TObject);
var
f:textfile;
fio,str:string;
im,jm:integer;
begin
assignfile(f,'in.txt');
reset(f);
readln(f,fio);
StringGrid2.Cells[0,0]:=fio;
readln(f,fio);
StringGrid2.Cells[0,1]:=fio;
readln(f,fio);
StringGrid2.Cells[0,2]:=fio;
// поиск максимального значения в 2-мерном массиве
// известны результаты спортсменов в трех попытках
// найти лучшую попытку и фамилию победителя
im:=1; jm:=1;
for k:=1 to 3 do
for l:=0 to 2 do begin
b[k,l]:=random(50);
StringGrid2.Cells[k,l]:=inttostr(b[k,l]);
if b[k,l]> b[im,jm] then begin
im:=k;
jm:=l;
label9.Caption:=inttostr(b[im,jm])+' '+StringGrid2.Cells[0,im-1];
end;
end;
end;