AMALIY MASALA.
1-misol->
Masala: Quyida biz odamlar yoshlarini hisoblovchi dastur tuzamiz. Bu masalada perfiks va postfikslarning uslubi qo’llaniladi. Bizlar oldiniga “myAge” o’zgaruvchi qiymatini kiritamiz va u 1 yil o’tib yo’shni ko’rsatadi. So’ngra yana 1 yildan keying yoshni ko’rsatadi.
Dastur kodi:
#include
using namespace std;
int main()
{
int myAge=39;
int yourAge=39;
cout << "Men" << myAge << "yoshdaman" << endl;
cout << "Siz" << yourAge <<"yoshdasiz" << endl;
myAge++ ; // postfiksli inkrement
++yourAge; // prefeksli inkrement
cout << "Bir yil o'tdi" << endl;
cout << "Men" << myAge <<"yoshdaman" << endl;
cout << "Siz" << yourAge <<"yoshdasiz" << endl;
cout << "Yana bir yil o'tdi" << endl;
cout << "Men" << myAge++ <<"yoshdaman" << endl;
cout << "Siz" <<++yourAge<<"yoshdasiz" << endl;
cout << "Ma'lumotlarni qaytadan" << endl;
cout << "chiqaraylik" << endl;
cout << "Men" << myAge <<"yoshdaman" << endl;
cout << "Siz" <return 0;
}
Natija:
2-misol-
Masala: Bu dastur berilgan sonlarning inkrementlangan turlarini postfikslash uslubi orqali hisoblovchi dastur. Unda k, m, l o’zgaruvchilarining qiymatlarini kiritish lozim va natija qabul qilinadi. Dastur quyidagicha ifodalanadi:
Dastur blok sxemasi:
Dastur kodi:
//
#include
#pragma hdrstop
#include "Unit1.h"
//
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//
void __fastcall TForm1::Button1Click(TObject *Sender)
{
double k,l,m;
k=StrToFloat(Edit1->Text);
l=StrToFloat(Edit2->Text);
m=StrToFloat(Edit3->Text);
k++;
Label4->Caption = "K= " + FloatToStrF(k,ffGeneral,10,2);
l+=4;
Label5->Caption = "L= " + FloatToStrF(l,ffGeneral,10,2);
m=m+k+(++l);
Label6->Caption = "M= " + FloatToStrF(m,ffGeneral,10,2);
}
//
void __fastcall TForm1::Edit1KeyPress(TObject *Sender, char &Key)
{
if((Key >= '0') && (Key <= '9'))
return;
if(Key == DecimalSeparator)
{
if((Edit1->Text).Pos(DecimalSeparator) != 0)
Key=0;
return;
}
if(Key==VK_BACK)
return;
if(Key==VK_RETURN)
{
Edit2->SetFocus();
return;
}
Key=0;
}
//
void __fastcall TForm1::Edit2KeyPress(TObject *Sender, char &Key) {
if((Key >= '0') && (Key <= '9'))
return;
if(Key == DecimalSeparator)
{
if((Edit2->Text).Pos(DecimalSeparator) != 0)
Key=0;
return;
}
if(Key==VK_BACK)
return;
if(Key==VK_RETURN)
{
Edit3->SetFocus();
return;
}
Key=0;
}
//
void __fastcall TForm1::Edit3KeyPress(TObject *Sender, char &Key)
{
if((Key >= '0') && (Key <= '9'))
return;
if(Key == DecimalSeparator)
{
if((Edit3->Text).Pos(DecimalSeparator) != 0)
Key=0;
return;
}
if(Key==VK_BACK)
return;
if(Key==VK_RETURN)
{
Button1->SetFocus();
return;
}
Key=0;
}
//
Do'stlaringiz bilan baham: |