1-dedline. Kalkulyator dasturini tayyorlash
Download 0.52 Mb.
|
kalkulyator
- Bu sahifa navigatsiya:
- Align
1-dedline. Kalkulyator dasturini tayyorlash. Men Kalkulyator dasturini tayyorlash uchun C++ Builder dasturlash muhitidan foydalandim brinchi kalkuyator interfeysi va menu ni yaratib oldim Kerakli raqamlarni joyladim. 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 keltirdim. . 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 #include "Unit1.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource "*.dfm" TForm1 *Form1; int amal=1; float bir_son,ikki_son, natija=0; String uzunlik; //--------------------------------------------------------------------------- __fastcall TForm1::TForm1(TComponent* Owner) : TForm(Owner) { } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton5Click(TObject *Sender) { if (Label1->Caption== "0") { Label1 ->Caption ="1"; } else Label1 -> Caption = Label1 ->Caption + "1"; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton6Click(TObject *Sender) { if (Label1->Caption== "0") { Label1 ->Caption ="2"; } else Label1 -> Caption = Label1 ->Caption + "2"; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton7Click(TObject *Sender) { if (Label1->Caption== "0") { Label1 ->Caption ="3"; } else Label1 -> Caption = Label1 ->Caption + "3"; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton9Click(TObject *Sender) { if (Label1->Caption== "0") { Label1 ->Caption ="4"; } else Label1 -> Caption = Label1 ->Caption + "4"; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton10Click(TObject *Sender) { if (Label1->Caption== "0") { Label1 ->Caption ="5"; } else Label1 -> Caption = Label1 ->Caption + "5"; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton11Click(TObject *Sender) { if (Label1->Caption== "0") { Label1 ->Caption ="6"; } else Label1 -> Caption = Label1 ->Caption + "6"; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton13Click(TObject *Sender) { if (Label1->Caption== "0") { Label1 ->Caption ="7"; } else Label1 -> Caption = Label1 ->Caption + "7"; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton14Click(TObject *Sender) { if (Label1->Caption== "0") { Label1 ->Caption ="8"; } else Label1 -> Caption = Label1 ->Caption + "8"; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton15Click(TObject *Sender) { if (Label1->Caption== "0") { Label1 ->Caption ="9"; } else Label1 -> Caption = Label1 ->Caption + "9"; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton1Click(TObject *Sender) { if (Label1->Caption!="0") { Label1 -> Caption = Label1 ->Caption + "0"; } } //-------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton8Click(TObject *Sender)
void __fastcall TForm1::SpeedButton12Click(TObject *Sender) { amal=2; bir_son=Label1->Caption .ToDouble(); Label1 ->Caption ="0"; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton16Click(TObject *Sender) { amal=3; bir_son=Label1->Caption .ToDouble(); Label1 ->Caption ="0"; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton20Click(TObject *Sender) { amal=4; bir_son=Label1->Caption .ToDouble(); Label1 ->Caption ="0"; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton3Click(TObject *Sender) { int a; ikki_son=Label1 ->Caption.ToDouble() ; switch(amal) { case 1:natija = bir_son+ikki_son;break; case 2:natija = bir_son-ikki_son;break; case 3:natija = bir_son*ikki_son;break; case 4:natija = bir_son/ikki_son;break; } uzunlik = FloatToStr(natija); a= uzunlik.Length(); if(a>9) { Label1 ->Caption = uzunlik.Delete(9,a-9); } else Label1 ->Caption = natija; } //--------------------------------------------------------------------------- void __fastcall TForm1::SpeedButton4Click(TObject *Sender) { Label1 -> Caption = "0"; amal=1; bir_son =0; ikki_son=0; } //--------------------------------------------------------------------------- Barcha kodlar tugagach dasturmizni ishga tushirib quyidagi natijani oldim. Download 0.52 Mb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling