linkedin facebook linkedin facebook nod32

Delphida chiziqli misollarni yechish

Muallif: Mengliyev Shoydullo

Qo`shilgan sana: 2014-10-26

Delphi da chiziqli algoritmlarga doir dasturlar tuzish.

 

1.1-masala. Delphi da chiziqli dasturga misol sifatida arifmetik amallarni hisoblash dasturini ko’rib chiqamiz.
Bu dasturni tuzish uchun yangi formada kiritiladigan ikkita son uchun aloxida «oyna» ochamiz. Buning uchun komponentalar ro’yxatidan Edit tanlanadi. Edit da kiritiladigan ma’lumotlar matnli ma’lumot bo’ladi, shuning uchun biz kiritgan matn shaklidagi sonlarni haqiqiy songa aylantirish kerak. Buning uchun Delphi da strtofloat(edit1.text) funkstiyasi ishlatiladi. Bunda strtofloat funkstiya nomi edit1.text esa argumenti. Biz hosil qilgan formaning ko’rinishi quyidagicha bo’ladi:

Bu formadagi birinchi son, ikkinchi son, Natija yozuvlari komponentalar ro’yxatidan Label ni tanlash bilan hosil qilingan. Odatda formada Label ishlatilsa, uning ishlatilish soniga qarab Label1, Label2 va hakazo shaklda chiqadi, buni o’zgartirish uchun Caption da Label1, Label2 va hakozolarni o’chirib o’rniga dasturga mos matn kiritiladi.
Formada qo’shish, ayrish, ko’paytirish, bo’lish amallariga standart tugmalardan Button komponentasi tanlangan. Bunda ham Caption da Button lar o’rniga mos ravishda qo’shish, ayrish, ko’paytirish, bo’lish deb o’zgartirilgan.
Delphi da tuzilgan dasturdan normal holda chiqib ketish uchun standart x tugmasidan tashqari yana boshqa tugma ishltiladi. Buning uchun komponentalar menyu satridan Additional bandi tanlanadi va uning ichidan BitBtn komponentasi tanlanadi. Agar Caption da &Close deb o’zgartirila, Kind da Bkclose deb yozib qo’ysak, u holda yopish tugmasida tagiga chizilgan Close yozuvi hosil bo’ladi.
Amallarni bajarib, natijani olish uchun mos tugmalarning ustida sichqonchaning chap tugmasini ikki marta bosilsa, u holda shu tugmaga mos bo’lgan prosteduraning ichiga avtomatik kiriladi. Bunda har bir tugmaga mos bo’lgan prosteduralarning ko’rinishi quyidagicha bo’ladi:
procedure TForm1.Button1Click(Sender: TObject);
begin
label3.Caption:=floattostr(strtofloat(edit1.Text)+ strtofloat(edit2.Text));
end;
procedure TForm1.Label3Click(Sender: TObject);
begin
label3.Caption:=floattostr(strtofloat(edit1.Text)- strtofloat(edit2.Text));
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
label3.Caption:=floattostr(strtofloat(edit1.Text)* strtofloat(edit2.Text));
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
label3.Caption:=floattostr(strtofloat(edit1.Text)/strtofloat(edit2.Text));
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
label3.Caption:=floattostr(strtofloat(edit1.Text)- strtofloat(edit2.Text));
end;
Bu dastur bajarilgandan keyingi ekranda hosil bo’ladigan natijaning ko’rinishi quyidagicha bo’ladi:

1.2-masala. A va B ikkita haqiqy sonlar berilgan. Ularning yig`indisi va ko’paytmasini hisoblash dasturini tuzing

Dastur matni
procedure TForm1.Button1Click(Sender: TObject);
var a,b,s,p:real;
begin
a:=StrToFloat(Edit1.Text);
b:=StrToFloat(Edit2.Text);
s:=a+b;
p:=a*b;
Edit3.Text:=FloatToStr(s);
Edit4.Text:=FloatToStr(p);
end;
end.

1.3-masala. Ikkita musbat son berilgan, bu sonlarning o’rta arifmetik va o’rta geometrik qiymatlarini hisoblash dasturini tuzing.

Dastur matni
procedure TForm1.Button1Click(Sender: TObject);
var a,b,s,p:real;
begin
a:=StrToFloat(Edit1.Text);
b:=StrToFloat(Edit2.Text);
s:=(a+b)/2;
p:=sqrt(a*b);
Edit3.Text:=FloatToStr(s);
Edit4.Text:=FloatToStr(p);
end;
end.

1.4-masala. Tomonlari a va b ga teng bo’lgan to’g’ri to’rtburchakning yuzi va peremetrini hisoblash dasturini tuzing.

Dastur matni
procedure TForm1.Button1Click(Sender: TObject);
var
a,b,s,p: real;
begin
a:=StrToFloat(Edit1.Text);
b:=StrToFloat(Edit2.Text);
s:=a*b; p:=2*(a+b);
Edit3.Text:=FloatToStr(s);
Edit4.Text:=FloatToStr(p);
End; end.

1.5-masala. Teng tomonli uchburchakning tomoni A ga teng. Uchburchakning yuzini topish dasturini tuzing.

Dastur matni
procedure TForm1.Button1Click(Sender: TObject);
var a,s:real;
begin
a:=StrToFloat(Edit1.Text);
S:=(sqrt(3))*a*a/4;
Edit2.Text:=FloatToStr(S);
end;
end.

1.6-masala. Koordinatalari x1,y1 va x2, y2 ga teng bo’lgan nuqtalar orasidagi masofani hisoblash dasturini tuzing.

Dastur matni
procedure TForm1.Button1Click(Sender: TObject);
var x1,x2,y1,y2,d:real;
begin
x1:=StrToFloat(Edit1.Text);
x2:=StrToFloat(Edit2.Text);
y1:=StrToFloat(Edit3.Text);
y2:=StrToFloat(Edit4.Text);
d:=sqrt(sqr(x2-x1)+sqr(y2-y1));
Edit5.Text:=FloatToStr(d);
end;
end.

1.7-masala. Birinchi hadi a1, ayirmasi d, hadlari soni n ga teng arifmetik progressiyaning hadlarining yig’indisini hisoblash dasturini tuzing.

Dastur matni
procedure TForm1.Button1Click(Sender: TObject);
var a1,d,n,S: real;
begin
a1:=StrToFloat(Edit1.Text);
d:=StrToFloat(Edit2.Text);
n:=StrToFloat(Edit3.Text);
S:=(2*a1+d*(n-1))/2*n;
Edit4.Text:=FloatToStr(S);
end;
end.

1.8-masala. Birinchi hadi b, maxraji q va hadlari soni n ga teng geometrik progressiyaning hadlarining yig’indisi S ni hisoblash dasturini tuzing.

Dastur matni
procedure TForm1.Button1Click(Sender: TObject);
var B,N,Q,S:real;
begin
B:=StrToFloat(Edit1.Text);
Q:=StrToFloat(Edit2.Text);
N:=StrToFloat(Edit3.Text);
S:=(B*(1-exp(N*ln(Q))))/(1-Q);
Edit4.Text:=FloatToStr(S);
end;
end.

1.9-masala. Berilgan sonning butun qismini aniqlang.

Dastur matni
procedure TForm1.Button1Click(Sender: TObject);
var a,b,s:real;
begin
a:=StrToFloat(Edit1.Text);
b:=StrToFloat(Edit2.Text);
s:=a div b;
Edit3.Text:=FloatToStr(s);
end;
end.

1.10-masala. Bir tomoni va unga yopishgan ikkita burchagi berilgan uchburchakning uchinchi burchagi va qolgan ikki tomonini aniqlang.

Dastur matni

procedure TForm1.Button1Click(Sender: TObject);
var a,ab,bb,b,c,cb:real;
begin
a:=StrToFloat(Edit1.Text);
ab:=StrToFloat(Edit2.Text);
bb:=StrToFloat(Edit3.Text);
cb:=pi-ab*pi/180-bb*pi/180;
b:=a*sin(bb)/sin(ab);
c:=a*sin(cb)/sin(ab);
Edit4.Text:=FloatToStr(cb);
Edit5.Text:=FloatToStr(b);
Edit6.Text:=FloatToStr(c);
end;

1213 marta o`qildi.

Parol:
Eslab qolish.


Ro`yhatdan o`tish

testing

+998915878681

Siz o`z maxsulotingizni 3D reklama ko`rinishda bo`lishini xohlaysizmi? Unda xamkorlik qilamiz.

3D Reklama


Рейтинг@Mail.ru
Рейтинг@Mail.ru

Besucherzahler
счетчик посещений