Boralnd delphi 7 dasturlash muhitida geometric masalalar yechish.
Masalaning matematik modulini tuzamiz: Uchta tomoni uzunligiga ko`ra uchburchak yuzini toppish uchun Geron formulasidan foydalanamiz:
Dastur ilovasini yaratishimiz uchun bizga 4 ta label, 3 ta edit va 1 ta button kompanentalari kerak bo`ladi.
Va bizga quyidagicha oyna hosil bo`ladi:
Button1 ni ikki marta bosib dastur kodi oynasiga quyidagilarni kiritamiz:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Label4: TLabel;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
a,b,c,p,S:real;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
begin
a:=strtoint(edit1.Text);
b:=strtoint(edit2.Text);
c:=strtoint(edit3.Text);
p:=(a+b+c)/2;
S:=sqrt(p*(p-a)*(p-b)*(p-c));
label4.Caption:='Uchburchakning yuzi:'+floattostr(s);
end;
end.
F9 funksional tugmasini bosish orqali dastur natijasini chiqaramiz.
7 – sinf geometriya faniga oid masalalar yechuvchi ilovalar yaratish.
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;
Xulosa
Bugungi kunda Informatika va axborot kommunikatsiya texnologiyalari sohasi jadal rivojlanmoqda, shu bilan birgalikda kompyuter tarmoqlari ham. Biz yoshlar o’zimiz va o’zimizdan keyingi avlodlarga Informatika va axborot kommunikatsiya texnologiyalari sirlarini chuqurroq o’rganishlari uchun yordam berishimiz kerak.
Men bu kurs ishini yozish va bu dasturni yaratish davomida o’z bilim va ko’nikmalarimni oshirib oldim. Bu dasturni yaratishda Delphi 7 dasturlash tilining men uchun yangi komponentalari bilan tanishdim va kompyuter tarmoqlari boyicha ham yangi bilimlarga ega bo’ldim.
Do'stlaringiz bilan baham: |