1-dedline. Kalkulyator dasturini tayyorlash



Download 191,93 Kb.
Sana30.04.2022
Hajmi191,93 Kb.
#597038
Bog'liq
1-dedline Ikromov o\'tkirbek (wecompress.com)

    Bu sahifa navigatsiya:
  • Align

1-dedline. Kalkulyator dasturini tayyorlash.
Men Kalkulyator dasturini tayyorlash uchun C++ Builder dasturlash muhitining Rad Studio XE3 versiyasidan foydalandim. C++ Builderda yangi loyiha yaratamiz:

Dastlab Kalkulyator dasturini interfeysini yaratib olamiz. Dastlab formaga dasturimiz ko’rinishi chiroyliroq va va yaratish davomida qulay bo’lishi uchun 2 ta Panel joylaymiz birinchisini ekran sifatida ishlatamiz ikkinchisini esa tugmalar uchun ishlatamiz. Birinchi Panelga 3ta Label komponentini joylamymiz. Birinchi Label komponentasini joylashtib kalkulyator ekrani sifatida foydalanish uchun uning Align xuxusiyatini alTopga, Alignment xususiyatini taRightJustifyga, Caption xuxusiyatini “0” ga o’zgartirib, so’ng xotira uchun yana bitta Label joylaymiz uni ham xususiyatlarini 1-Label kabi qilamiz faqat font dan rangini ozgartirib qo’yamiz , endi esa so’ngi Labelni joylaymiz bu esa M ya’ni xotir aishlaganini bizga ko’rsatib turish uchun hizmat qiladi unu chap tomonga joylaymiz va ko’rinishni yuidagi xolatga keltiramiz:


Bu holatga kelgandan so’ng asosiy labeldan boshqa labellarni Captionini o’chirib tashlaymi, chunki kodlar yozish orqali kerakli paytda nom qo’yib olamiz.


So’ng 2-Panelga barcha kerakli tugmalarni joylaymiz, tugmalar sifatida SpeedButton dan foydalanamiz chunki uning imkoniyatlari ancha keng,song dasturimiz quyidagi holatga keladi:

Ana endi barcha tugmalarimiz kod yozishga tayyor bo’lib turibdi. Endi tugmalarga kerakli kodlarni yozib chiqamiz, albatta vazifasiga qarab.


Avval raqamlarni ekranga chiqarish uchun kodlar yozib chiqamiz, so’ng Sender funksiyasi orqali boshqa raqamlarga ham ulab qo’yamiz, undan so’ng ammalarning tugmalariga kodlar yozamiz. Keyin esa tenglik tugmasini kodimni yozamiz,song boshqa tugmalarga navbatdan kodlar yozamiz.
Dastur kodi:
//--
#include
#pragma hdrstop

#include "Unit1.h"


//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
int iAmal=0;
float birinchiSon, ikkinchiSon, natija;
bool bAmal=False;-------------------------------------------------------------------------

//---------------------------------------------------------------------------


__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton9Click(TObject *Sender)


{
if(bAmal)
LABEL->Caption="0";
if(LABEL->Caption=="0"){
LABEL->Caption=((TSpeedButton * )Sender)->Caption;
Label1->Caption=Label1->Caption+((TSpeedButton * )Sender)->Caption;}

else if (LABEL->Caption.Pos("-")!=0 && LABEL->Caption.Pos(".")!=0 && LABEL->Caption.Length() < 10 ) {


LABEL->Caption=LABEL->Caption+((TSpeedButton * )Sender)->Caption;
Label1->Caption=Label1->Caption+((TSpeedButton * )Sender)->Caption;}
else if (LABEL->Caption.Pos("-")==0 && LABEL->Caption.Pos(".")!=0 && LABEL->Caption.Length() <9) {
LABEL->Caption=LABEL->Caption+((TSpeedButton * )Sender)->Caption;
Label1->Caption=Label1->Caption+((TSpeedButton * )Sender)->Caption;}

else if (LABEL->Caption.Pos("-")!=0 && LABEL->Caption.Pos(".")== 0 && LABEL->Caption.Length() <9) {


LABEL->Caption=LABEL->Caption+((TSpeedButton * )Sender)->Caption;
Label1->Caption=Label1->Caption+((TSpeedButton * )Sender)->Caption;}

else if(LABEL->Caption.Length()< 8){


LABEL->Caption=LABEL->Caption+((TSpeedButton * )Sender)->Caption;
Label1->Caption=Label1->Caption+((TSpeedButton * )Sender)->Caption;}
bAmal=False;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton5Click(TObject *Sender)


{
if (LABEL->Caption !="0"){
double a=StrToFloat(LABEL->Caption) ;
a=a*(-1);
LABEL->Caption= FloatToStr(a) ;
Label1->Caption= "-("+Label1->Caption+")" ;
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton6Click(TObject *Sender)


{
if (LABEL->Caption != "0" && LABEL->Caption.Pos("-")!=0 && LABEL->Caption.Length() <9 ) {
LABEL->Caption=LABEL->Caption +"0"; }
else if (LABEL->Caption != "0" && LABEL->Caption.Length() <8 ) {
LABEL->Caption=LABEL->Caption +"0"; }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton27Click(TObject *Sender)


{
LABEL->Caption="0";
Label1->Caption="";
bAmal=False;
iAmal=0;
}

//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton7Click(TObject *Sender)
{
if (LABEL->Caption.Pos(".") == 0) {
LABEL->Caption=LABEL->Caption+ ".";
Label1->Caption=Label1->Caption+ ".";
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton28Click(TObject *Sender)


{
if (LABEL->Caption != "0" ) {
if (LABEL->Caption.Length()==1) {
LABEL->Caption="0";
Label1->Caption="";}
else {LABEL->Caption=LABEL->Caption.SubString(0, LABEL->Caption.Length()-1);
Label1->Caption=Label1->Caption.SubString(0, Label1->Caption.Length()-1); }}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton21Click(TObject *Sender)


{
if (LABEL->Caption!="0") {
double a;
a=StrToFloat(LABEL->Caption);
a=1/a;
LABEL->Caption= FloatToStr(a); }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton22Click(TObject *Sender)


{
if (LABEL->Caption!="0") {
double a;
a=StrToFloat(LABEL->Caption);
a=a*a;
LABEL->Caption= FloatToStr(a); }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton25Click(TObject *Sender)


{
if (LABEL->Caption!=0) {
if (LABEL->Caption!="0") {
double a;
a=StrToFloat(LABEL->Caption);
a=a/100;
LABEL->Caption= FloatToStr(a); }
}
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton12Click(TObject *Sender)


{

bAmal=True;


String s;
s=(((TSpeedButton*)Sender)->Caption);

if(s=="+")


iAmal=1;
if(s=="-")
iAmal=2;
if(s=="*")
iAmal=3;
if(s=="/")
iAmal=4;
Label1->Caption=Label1->Caption+s;
birinchiSon=StrToFloat(LABEL->Caption);

}
//---------------------------------------------------------------------------


void __fastcall TForm1::SpeedButton8Click(TObject *Sender)


{
ikkinchiSon=StrToFloat(LABEL->Caption);
switch (iAmal) {
case 1: natija=birinchiSon+ikkinchiSon;
LABEL->Caption=FloatToStr(natija); break;
case 2: natija=birinchiSon-ikkinchiSon;
LABEL->Caption=FloatToStr(natija); break;
case 3: natija=birinchiSon*ikkinchiSon;
LABEL->Caption=FloatToStr(natija); break;
case 4: natija=birinchiSon/ikkinchiSon;
LABEL->Caption=FloatToStr(natija); break;

default:
;


}
if(LABEL->Caption.Length()>=15)
LABEL->Caption=LABEL->Caption.SubString(0, LABEL->Caption.Pos(",")+8);

}
//---------------------------------------------------------------------------


void __fastcall TForm1::SpeedButton23Click(TObject *Sender)


{
if (LABEL->Caption!="0") {
double a;
a=StrToFloat(LABEL->Caption);
a= sqrt(a);
LABEL->Caption= FloatToStr(a); }
}
//---------------------------------------------------------------------------

void __fastcall TForm1::SpeedButton26Click(TObject *Sender)


{
LABEL->Caption="0";
bAmal=False;
iAmal=0;
}
//---------------------------------------------------------------------------

void __fastcall TForm1::Timer1Timer(TObject *Sender)


{
SpeedButton3->Caption=Now();
SpeedButton3->Caption=SpeedButton3->Caption.SubString(SpeedButton3->Caption.Length()-10, SpeedButton3->Caption.Length());
}
//---------------------------------------------------------------------------

Download 191,93 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish