2 va 3-rasm. Dastur ishlash jarayonidan lavhalar.
Ilova
Dasturning kod qsimi:
//---------------------------------------------------------------------
#include
#pragma hdrstop
#include "kalkulator.h"
//---------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
double birinchison,ikkinchison,natija;
int amal=0;
/*
1 qoshish
2 ayrish
3 kopaytirish
4 bolish
*/
bool amalbosildi=false;
bool raqambosildi=false;
int tengbosildi=0;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------void __fastcall TForm1::btn1Click(TObject *Sender)
{
int displayLength=10;
raqambosildi=true;
tengbosildi=0;
if(stdisplay->Caption.Pos(",")!=0){
displayLength++;
}
if(stdisplay->Caption.Pos("-")!=0){
displayLength++;
}
if(amalbosildi){
amalbosildi=false;
stdisplay->Caption=((TSpeedButton*)Sender)->Caption;
}else{
if(stdisplay->Caption=="0") {
stdisplay->Caption=((TSpeedButton*)Sender)->Caption;
}else{
if(stdisplay->Caption.Length() stdisplay->Caption=stdisplay->Caption+((TSpeedButton*)Sender)->Caption;}
}
}
}
//---------------------------------------------------------------------
void __fastcall TForm1::btn0Click(TObject *Sender)
{
raqambosildi=true;
tengbosildi=0;
int displayLength=10;
if(stdisplay->Caption.Pos(",")!=0){
displayLength++;
}
if(stdisplay->Caption.Pos("-")!=0){
displayLength++;
}
if(amalbosildi){
amalbosildi=false;
stdisplay->Caption="0";
}else{
if(stdisplay->Caption!="0") {
if(stdisplay->Caption.Length()
stdisplay->Caption=stdisplay->Caption+"0";
}
}
}
}
//--------------------------------------------------------------------
void __fastcall TForm1::btndeleteClick(TObject *Sender)
{
if(stdisplay->Caption.Length()==1){
stdisplay->Caption="0";
}else
stdisplay->Caption= stdisplay->Caption.SubString(1,stdisplay->Caption.Length()-1) ;
}
//---------------------------------------------------------------------
void __fastcall TForm1::btnvergulClick(TObject *Sender)
{
raqambosildi=true;
tengbosildi=0;
if(amalbosildi){
amalbosildi = false;
stdisplay->Caption="0," ;
}else{
if(stdisplay->Caption.Pos(",")==0) {
stdisplay->Caption= stdisplay->Caption+"," ;
}
}
}
//---------------------------------------------------------------------
void __fastcall TForm1::btnishoraClick(TObject *Sender)
{
tengbosildi=0;
stdisplay->Caption=FloatToStr(StrToFloat(stdisplay->Caption)*(-1));
}
//---------------------------------------------------------------------
void __fastcall TForm1::FormKeyPress(TObject *Sender, System::WideChar &Key)
{
if (Key == '0'){
btn0->Click();
} else if (Key == '1'){
btn1->Click();
} else if (Key == '2'){
btn2->Click();
} else if (Key == '3'){
btn3->Click();
} else if (Key == '4'){
btn4->Click();
} else if (Key == '5'){
btn5->Click();
} else if (Key == '6'){
btn6->Click();
} else if (Key == '7'){
btn7->Click();
} else if (Key == '8'){
btn8->Click();
} else if (Key == '9'){
btn9->Click();
} else if (Key == ','){
btnvergul->Click();
} else if (Key == '.'){
btnvergul->Click();
} else if (Key == '='){
btnteng->Click();
} else if (Key == '+'){
btnqoshish->Click();
} else if (Key == '-'){
btnayrish->Click();
} else if (Key == '/'){
btnbolish->Click();
} else if (Key == '*'){
btnkopaytirish->Click();
} else if (Key == vkBack){
btndelete->Click();
} else if (Key == '%'){
btnfoiz->Click();
}
}
//---------------------------------------------------------------------
void __fastcall TForm1::btnqoshishClick(TObject *Sender)
{
tengbosildi=0;
amal=1 ;
amalbosildi=true;
if(amal !=0 && raqambosildi)
{ btnteng->Click();
raqambosildi=false; }
birinchison=StrToFloat(stdisplay->Caption);
}
//---------------------------------------------------------------------
void __fastcall TForm1::btnayrishClick(TObject *Sender)
{
tengbosildi=0;
amal=2 ;
amalbosildi=true;
if(amal !=0 && raqambosildi)
{ btnteng->Click();
raqambosildi=false; }
birinchison=StrToFloat(stdisplay->Caption);
}
//---------------------------------------------------------------------
void __fastcall TForm1::btnkopaytirishClick(TObject *Sender)
{
tengbosildi=0;
amal=3 ;
amalbosildi=true;
if(amal !=0 && raqambosildi)
{
btnteng->Click();
raqambosildi=false;}
birinchison=StrToFloat(stdisplay->Caption);
}
//---------------------------------------------------------------------
void __fastcall TForm1::btnbolishClick(TObject *Sender)
{
tengbosildi=0;
if(amal !=0 && raqambosildi)
{ btnteng->Click();
raqambosildi=false; }
amal=4 ;
amalbosildi=true;
birinchison=StrToFloat(stdisplay->Caption);
}
//---------------------------------------------------------------------
void __fastcall TForm1::btnceClick(TObject *Sender)
{
tengbosildi=0;
stdisplay->Caption="0";
}
//---------------------------------------------------------------------
void __fastcall TForm1::btntengClick(TObject *Sender)
{
tengbosildi++;
if(amal!=0 && !amalbosildi){
raqambosildi=false;
ikkinchison=StrToFloat(stdisplay->Caption) ;
switch(amal){
case 1: natija=birinchison+ikkinchison;
break;
case 2: natija=birinchison-ikkinchison;
break;
case 3: natija=birinchison*ikkinchison;
break;
case 4: natija=birinchison/ikkinchison;
break;
}
stdisplay->Caption=FloatToStr(natija);
if(tengbosildi==1){
birinchison=ikkinchison;
}
}
}
//---------------------------------------------------------------------
void __fastcall TForm1::btncClick(TObject *Sender)
{
amal=0;
raqambosildi=false;
amalbosildi=false ;
stdisplay->Caption="0";
}
//---------------------------------------------------------------------
void __fastcall TForm1::btnteskariClick(TObject *Sender)
{
stdisplay->Caption=FloatToStr(1/StrToFloat(stdisplay->Caption ));
}
//---------------------------------------------------------------------void __fastcall TForm1::btnsqrClick(TObject *Sender)
{
stdisplay->Caption=FloatToStr(StrToFloat(stdisplay->Caption)*StrToFloat(stdisplay->Caption));
}
//---------------------------------------------------------------------
void __fastcall TForm1::btnsqrtClick(TObject *Sender)
{
stdisplay->Caption=FloatToStr(sqrt(StrToFloat(stdisplay->Caption)));
}
//---------------------------------------------------------------------
void __fastcall TForm1::btnfoizClick(TObject *Sender)
{
if(amal==3 && !amalbosildi){
raqambosildi=false;
tengbosildi=0;
ikkinchison=StrToFloat(stdisplay->Caption) ;
natija=birinchison*ikkinchison/100;
stdisplay->Caption=FloatToStr(natija); }
}
//---------------------------------------------------------------------
Do'stlaringiz bilan baham: |