1-LABORATORIYA ISHI
“C++ Builder” dasturida arifmetik amallarni bajaruvchi dastur tuzish
612-17, Qodirov Ahmadxon
Amaliy qism
Arifmetik amallarni bajaruvchi dasturni tuzish uchun bizga uchta matn tahrirlash maydoni va 4 ta tugma kerak bo’ladi. Ularni ixtiyorimizga ko’ra tartiblaymiz hamda matn shriftini, o’lchamlarini tanlaymiz.
Endi esa tugmalarga kerakli buyruqlarni kiratamiz.
Qo’shish (+) tugmasi uchun:
float birinchi_son=StrToFloat(Edit1->Text);
float ikkinchi_son=StrToFloat(Edit2->Text);
Edit3->Text=FloatToStr(birinchi_son+ikkinchi_son);
Ayirish (-) tugmasi uchun:
float birinchi_son=StrToFloat(Edit1->Text);
float ikkinchi_son=StrToFloat(Edit2->Text);
Edit3->Text=FloatToStr(birinchi_son-ikkinchi_son);
Ko’paytirish (*) tugmasi uchun:
float birinchi_son=StrToFloat(Edit1->Text);
float ikkinchi_son=StrToFloat(Edit2->Text);
Edit3->Text=FloatToStr(birinchi_son*ikkinchi_son);
Bo’lish (/) tugmasi uchun:
float birinchi_son=StrToFloat(Edit1->Text);
float ikkinchi_son=StrToFloat(Edit2->Text);
Edit3->Text=FloatToStr(birinchi_son/ikkinchi_son);
Umumiy kod:
//---------------------------------------------------------------------------
#include
#pragma hdrstop
#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
float birinchi_son=StrToFloat(Edit1->Text);
float ikkinchi_son=StrToFloat(Edit2->Text);
Edit3->Text=FloatToStr(birinchi_son+ikkinchi_son);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button2Click(TObject *Sender)
{
float birinchi_son=StrToFloat(Edit1->Text);
float ikkinchi_son=StrToFloat(Edit2->Text);
Edit3->Text=FloatToStr(birinchi_son-ikkinchi_son);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button3Click(TObject *Sender)
{
float birinchi_son=StrToFloat(Edit1->Text);
float ikkinchi_son=StrToFloat(Edit2->Text);
Edit3->Text=FloatToStr(birinchi_son*ikkinchi_son);
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button4Click(TObject *Sender)
{
float birinchi_son=StrToFloat(Edit1->Text);
float ikkinchi_son=StrToFloat(Edit2->Text);
Edit3->Text=FloatToStr(birinchi_son/ikkinchi_son);
}
//---------------------------------------------------------------------------
D asturni ishga tushiramiz. Quyida dastur barcha arifmetik amallarni to’g’ri bajarayotganini ko’rishimiz mumkin.
Natija qismidagi matn tahrirlash maydonini belgilab, “Object inspector” orqali ReadOnly qatoriga tushib, uni truega o’zgartirish orqali u yerdagi hosil bo’lgan natijani faqat o’qish uchun mo’ljallaymiz.
Do'stlaringiz bilan baham: |