1-dedline. Kalkulyator dasturini tayyorlash.
Men Kalkulyator dasturini tayyorlash uchun C++ Builder dasturlash muhitining Rad Studio XE2 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 TButton 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 "Unit8.h"
//---------------------------------------------------------------------------
double a,b,c,ishora;
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm8 *Form8;
//---------------------------------------------------------------------------
__fastcall TForm8::TForm8(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm8::Button15Click(TObject *Sender)
{
Edit1->Text=Edit1->Text+Button15->Caption;
}
//---------------------------------------------------------------------------
void __fastcall TForm8::Button14Click(TObject *Sender)
{
Edit1->Text=Edit1->Text+Button14->Caption;
}
//---------------------------------------------------------------------------
void __fastcall TForm8::Button13Click(TObject *Sender)
{
Edit1->Text=Edit1->Text+Button13->Caption;
}
//---------------------------------------------------------------------------
void __fastcall TForm8::Button11Click(TObject *Sender)
{
Edit1->Text=Edit1->Text+Button11->Caption;
}
//---------------------------------------------------------------------------
void __fastcall TForm8::Button17Click(TObject *Sender)
{
Edit1->Clear();
}
//---------------------------------------------------------------------------
void __fastcall TForm8::Button1Click(TObject *Sender)
{
Edit1->Text=Edit1->Text+Button1->Caption;
}
//---------------------------------------------------------------------------
void __fastcall TForm8::Button2Click(TObject *Sender)
{
Edit1->Text=Edit1->Text+Button2->Caption;
}
//---------------------------------------------------------------------------
void __fastcall TForm8::Button4Click(TObject *Sender)
{
Edit1->Text=Edit1->Text+Button4->Caption;
}
//---------------------------------------------------------------------------
void __fastcall TForm8::Button5Click(TObject *Sender)
{
Edit1->Text=Edit1->Text+Button5->Caption;
}
//---------------------------------------------------------------------------
void __fastcall TForm8::Button6Click(TObject *Sender)
{
Edit1->Text=Edit1->Text+Button6->Caption;
}
//---------------------------------------------------------------------------
void __fastcall TForm8::Button8Click(TObject *Sender)
{
Edit1->Text=Edit1->Text+Button8->Caption;
}
//---------------------------------------------------------------------------
void __fastcall TForm8::Button16Click(TObject *Sender)
{
a=Edit1->Text.ToDouble();
Edit1->Clear();
ishora=1;
}
//---------------------------------------------------------------------------
void __fastcall TForm8::Button9Click(TObject *Sender)
{
b=Edit1->Text.ToDouble();
if (ishora==1) {c=a+b;}
if(ishora==2){c=a-b;}
if(ishora==3){c=a*b;}
if(ishora==4){c=a/b;}
Edit1->Text=c;
}
//---------------------------------------------------------------------------
void __fastcall TForm8::Button7Click(TObject *Sender)
{
a=Edit1->Text.ToDouble();
Edit1->Clear();
ishora=2;
}
//---------------------------------------------------------------------------
void __fastcall TForm8::Button3Click(TObject *Sender)
{
a=Edit1->Text.ToDouble();
Edit1->Clear();
ishora=3;
}
//---------------------------------------------------------------------------
void __fastcall TForm8::Button12Click(TObject *Sender)
{
a=Edit1->Text.ToDouble();
Edit1->Clear();
ishora=4;
}
//---------------------------------------------------------------------------
void __fastcall TForm8::Edit1Change(TObject *Sender)
{
}
//---------------------------------------------------------------------------
Do'stlaringiz bilan baham: |